Search Results

Search found 491 results on 20 pages for 'jframe'.

Page 5/20 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to keep Java Frame from waiting?

    - by pypmannetjies
    I am writing a genetic algorithm that approximates an image with a polygon. While going through the different generations, I'd like to output the progress to a JFrame. However, it seems like the JFrame waits until the GA's while loop finishes to display something. I don't believe it's a problem like repainting, since it eventually does display everything once the while loop exits. I want to GUI to update dynamically even when the while loop is running. Here is my code: while (some conditions) { //do some other stuff gui.displayPolygon(best); gui.displayFitness(fitness); gui.setVisible(true); } public void displayPolygon(Polygon poly) { BufferedImage bpoly = ImageProcessor.createImageFromPoly(poly); ImageProcessor.displayImage(bpoly, polyPanel); this.setVisible(true); } public static void displayImage(BufferedImage bimg, JPanel panel) { panel.removeAll(); panel.setBounds(0, 0, bimg.getWidth(), bimg.getHeight()); JImagePanel innerPanel = new JImagePanel(bimg, 25, 25); panel.add(innerPanel); innerPanel.setLocation(25, 25); innerPanel.setVisible(true); panel.setVisible(true); }

    Read the article

  • How can I change jtable height at runtime

    - by wniroshan
    I hava a JFrame with multiple JPanels of similar width aligned one below other. I use one of these JPanels to display a JTable which is the last JPanel of the lot. This JPanel has a JScrollpane as a child component. This is where I try to add my table dynamically. Initial height of this JScrollpane is set to 40. I designed above template using Netbeans 6.8 Now I'm trying to add the table to the JPanel. When a button is pressed below code snippet is called. The class which includes this code extends javax.swing.JFrame class. I am expecting below code would adjust table height according to the row count and display the table. SearchTable = new JTable(RowData, DisplayNames) { @Override public boolean isCellEditable(int rowIndex, int vColIndex) { return false; } }; // if row count is less than 10 then display all the rows without a scroll bar if (SearchTable.getRowCount() < 10) { pnl_tblpanel.setPreferredSize(new Dimension(625, SearchTable.getRowHeight() * (SearchTable.getRowCount() + 4))); scr_tblholder.setPreferredSize(new Dimension(625, SearchTable.getRowHeight() * (SearchTable.getRowCount() + 4))); } else {// if row count is more than 10 display first 10 rows and add a scroll bar pnl_tblpanel.setPreferredSize(new Dimension(625, SearchTable.getRowHeight() * (10 + 2))); scr_tblholder.setAutoscrolls(true); } //pnl_tblpanel.add(scr_tblholder); scr_tblholder.setViewportView(SearchTable); //pnl_tblpanel.repaint(); pnl_tblpanel.validate(); this.validate(); //this.repaint(); pnl_tblpanel.setVisible(true); this.pack(); The table displays, but the table height is not changed according to the row count. It stays its default value. I have been trying many combinations of validate and repaint but nothing worked. (More in desperation) Can anyone shed some light on this Thank you

    Read the article

  • Jpanel didn't show rest of it's component

    - by Ali Amiri
    I have jfarame with a button and a JPanel as I named panel, I want after I clicked the button add an inner JPanel to my panel. But this but there is a problem with this! because after adding second panel it didn't add any other panel. my code is: import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.AbstractButton; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.GridLayout; import javax.swing.JTextField; public class DrawImages extends JFrame{ int i; public DrawImages() { JButton btnNewButton = new JButton("New button"); i = 0; getContentPane().add(btnNewButton, BorderLayout.SOUTH); setMinimumSize(new Dimension(1000,150)); final JPanel panel = new JPanel(); panel.setSize(995, 145); getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(null); final JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setBounds(0, 0, 46, 14); panel.add(lblNewLabel); btnNewButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent paramActionEvent) { JPanel panel_1 = new JPanel(); //getContentPane().add(panel_1, BorderLayout.NORTH); panel_1.setLayout(null); JLabel imagelable = new JLabel(new ImageIcon("c:\\good.jpg")); imagelable.setBounds(70, 5, 105, 65); panel_1.add(imagelable); JLabel lblNewLabel_4 = new JLabel("Up Label"); lblNewLabel_4.setBounds(5, 5, 65, 35); panel_1.add(lblNewLabel_4); JLabel lblNewLabel_2 = new JLabel("Down Label"); lblNewLabel_2.setBounds(5, 25, 65, 65); panel_1.add(lblNewLabel_2); lblNewLabel.setText(""+i); panel_1.setBounds(5+170*i, 5, 170+170*i, 70); panel.add(panel_1); i++; } }); panel.setMinimumSize(new Dimension(995,150)); } public static void main(String[]args) { DrawImages drawImages = new DrawImages(); drawImages.setVisible(true); } }

    Read the article

  • change a frame's attribute by pressing a button

    - by asavu
    Hi. Suppose we have a JFrame named frame1 with a String attribute named credentials set inittially to null. I have a jButton named button1 attached to the frame and I want to change the frame1 String credentials attribute by pressing button1. I need some piece of advice regarding the ActionListener code especially. Could you guys pls help me? Thank you.

    Read the article

  • Nothing happen when refreshing the main Frame (JAVA)

    - by Ams
    Hello everyone, I try to show a ( Logged in ) message when a user is succefully connected but nothing happen when a do a repaint(). you can take a look to the code : public class MainFrame extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private static final int FRAME_HEIGHT = 400; private static final int FRAME_WIDTH = 250; private static final String TITLE = new String("TweeX"); private static String TWITTERID = new String(); private static String TWITTERPW = new String(); private boolean logged = false; private JTextField loginField = new JTextField(10); private JPasswordField passField = new JPasswordField(10); private JButton login = new JButton("Connect"); private GridBagConstraints c = new GridBagConstraints(); private String UserStatus = new String("Please login..."); /* * Constructor ! */ MainFrame() { setSize(FRAME_WIDTH, FRAME_HEIGHT); setTitle(TITLE); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setResizable(false); loginUser(); } /* * Login Forms */ protected void loginUser(){ this.setLayout(new GridBagLayout()); //add Login Fiels + Label c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.insets = new Insets(5,5,5,20); c.gridy = 0; add(new JLabel("Username:"),c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 0; add(loginField,c); //add Password Fiels + Label c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 1; add(new JLabel("Password:"),c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; add(passField,c); //add Login button c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 2; add(login,c); //add listener to login button login.addActionListener((ActionListener) this); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 3; add(new JLabel(UserStatus),c); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { TWITTERID = loginField.getText(); TWITTERPW = passField.getText(); Twitter twitter = new TwitterFactory().getInstance(TWITTERID,TWITTERPW); logged = true; try { twitter.verifyCredentials(); } catch (TwitterException e1) { logged = false; } } protected void connect(){ if(logged){ UserStatus = "Loged In :)"; repaint(); } } static public void main(String[] argv) { new MainFrame(); } }

    Read the article

  • setting something disposed or invisible java

    - by OVERTONE
    this might be simple enough as just inserting the right method but i cant seem to get it right. i have a simple program with two buttons. each one changes the picture above them. but anytime i click the buttons i get some odd awt event queue error. i think its because im trying to add something to a frame after its already been made. package icnon; import javax.imageio.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class FrameIconExample extends JFrame implements ActionListener { JLabel j; JPanel p, l, k; JButton picOne, picTwo; Container cPane; public FrameIconExample() { JButton picOne = new JButton("picOne"); JButton picTwo = new JButton("picTwo"); picOne.setName("picOne"); picTwo.setName("picTwo"); picOne.addActionListener(this); picTwo.addActionListener(this); JPanel p = new JPanel(new GridLayout(2, 1)); JPanel l = new JPanel(new FlowLayout()); JPanel k = new JPanel(new FlowLayout()); cPane = getContentPane(); j = new JLabel(new ImageIcon("../meet/src/images/beautiful-closeup-portrait-photography.jpg")); l.add(j); k.add(picOne); k.add(picTwo); p.add(l); p.add(k); add(p); } public static void main(String[] args) { FrameIconExample frame = new FrameIconExample(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(300, 800)); frame.setTitle("Frame Icon Example"); // Display the form frame.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { JButton temp = (JButton) e.getSource(); String src = "../meet/src/images/Majken Kruse portrait - john.jpg"; //System.out.println(src + " " + temp.getName()); if(temp.getName().equalsIgnoreCase("picOne")) { src = "../meet/src/images/beautiful-closeup-portrait-photography.jpg"; System.out.println(src + " " + temp.getName()); Icon img; j = new JLabel(new ImageIcon(src)); l.add(j); System.out.println("1"); } if(temp.getName().equalsIgnoreCase("picTwo")) { src = "../icontest/images/Majken Kruse portrait - john.jpg"; System.out.println(src + " " + temp.getName()); Icon img; j = new JLabel(new ImageIcon(src)); l.add(j); System.out.println("2"); } } } its all just the one program so if you copy paste it into an editor you can see the stack trace. but the source of the image files wont be there. does anyone know how id do it? or where im goin wrong? stack trace: ../meet/src/images/beautiful-closeup-portrait-photography.jpg picOne Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at icnon.FrameIconExample.actionPerformed(FrameIconExample.java:68) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

    Read the article

  • login form whith java/sqlite

    - by tuxou
    hi I would like to create a login form for my application with the possibility to add or remove users for an sqlite database, i have created the table users(nam, pass) but i can't unclud it in my login form, it someone could help me this is my login code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class login extends JFrame { // Variables declaration private JLabel jLabel1; private JLabel jLabel2; private JTextField jTextField1; private JPasswordField jPasswordField1; private JButton jButton1; private JPanel contentPane; // End of variables declaration public login() { super(); create(); this.setVisible(true); } private void create() { jLabel1 = new JLabel(); jLabel2 = new JLabel(); jTextField1 = new JTextField(); jPasswordField1 = new JPasswordField(); jButton1 = new JButton(); contentPane = (JPanel)this.getContentPane(); // // jLabel1 // jLabel1.setHorizontalAlignment(SwingConstants.LEFT); jLabel1.setForeground(new Color(0, 0, 255)); jLabel1.setText("username:"); // // jLabel2 // jLabel2.setHorizontalAlignment(SwingConstants.LEFT); jLabel2.setForeground(new Color(0, 0, 255)); jLabel2.setText("password:"); // // jTextField1 // jTextField1.setForeground(new Color(0, 0, 255)); jTextField1.setSelectedTextColor(new Color(0, 0, 255)); jTextField1.setToolTipText("Enter your username"); jTextField1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jTextField1_actionPerformed(e); } }); // // jPasswordField1 // jPasswordField1.setForeground(new Color(0, 0, 255)); jPasswordField1.setToolTipText("Enter your password"); jPasswordField1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jPasswordField1_actionPerformed(e); } }); // // jButton1 // jButton1.setBackground(new Color(204, 204, 204)); jButton1.setForeground(new Color(0, 0, 255)); jButton1.setText("Login"); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); // // contentPane // contentPane.setLayout(null); contentPane.setBorder(BorderFactory.createEtchedBorder()); contentPane.setBackground(new Color(204, 204, 204)); addComponent(contentPane, jLabel1, 5,10,106,18); addComponent(contentPane, jLabel2, 5,47,97,18); addComponent(contentPane, jTextField1, 110,10,183,22); addComponent(contentPane, jPasswordField1, 110,45,183,22); addComponent(contentPane, jButton1, 150,75,83,28); // // login // this.setTitle("Login To Members Area"); this.setLocation(new Point(76, 182)); this.setSize(new Dimension(335, 141)); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.setResizable(false); } /** Add Component Without a Layout Manager (Absolute Positioning) */ private void addComponent(Container container,Component c,int x,int y,int width,int height) { c.setBounds(x,y,width,height); container.add(c); } private void jTextField1_actionPerformed(ActionEvent e) { } private void jPasswordField1_actionPerformed(ActionEvent e) { } private void jButton1_actionPerformed(ActionEvent e) { System.out.println("\njButton1_actionPerformed(ActionEvent e) called."); String username = new String(jTextField1.getText()); String password = new String(jPasswordField1.getText()); if(username.equals("") || password.equals("")) // If password and username is empty Do this { jButton1.setEnabled(false); JLabel errorFields = new JLabel("You must enter a username and password to login."); JOptionPane.showMessageDialog(null,errorFields); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); this.setVisible(true); } else { JLabel optionLabel = new JLabel("You entered "+username+" as your username. Is this correct?"); int confirm =JOptionPane.showConfirmDialog(null,optionLabel); switch(confirm){ // Switch Case case JOptionPane.YES_OPTION: // Attempt to Login user jButton1.setEnabled(false); // Set button enable to false to prevent 2 login attempts break; case JOptionPane.NO_OPTION: // No Case.(Go back. Set text to 0) jButton1.setEnabled(false); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); break; case JOptionPane.CANCEL_OPTION: // Cancel Case.(Go back. Set text to 0) jButton1.setEnabled(false); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); break; } // End Switch Case } } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ex) { System.out.println("Failed loading L&F: "); System.out.println(ex); } new login(); }; }

    Read the article

  • frame variable cannot be found

    - by Umzz Mo
    I am making 3 board games, and I have started my coding off in one class. Now that i wanted to move around it is giving me problems. In my view class I just want to have the main frame where users can pick from the games. And in the other views, i.e the childrens of view class i want to have the interface for the actual games. Now that the Jframe frame = new frame was created in the parent class, it cannot find the variable frame in the children classes.

    Read the article

  • login form with java/sqlite

    - by tuxou
    hi I would like to create a login form for my application with the possibility to add or remove users for an sqlite database, i have created the table users(nam, pass) but i can't unclud it in my login form, it someone could help me this is my login code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class login extends JFrame{ // Variables declaration private JLabel jLabel1; private JLabel jLabel2; private JTextField jTextField1; private JPasswordField jPasswordField1; private JButton jButton1; private JPanel contentPane; // End of variables declaration public login(){ super(); create(); this.setVisible(true); } private void create(){ jLabel1 = new JLabel(); jLabel2 = new JLabel(); jTextField1 = new JTextField(); jPasswordField1 = new JPasswordField(); jButton1 = new JButton(); contentPane = (JPanel)this.getContentPane(); // // jLabel1 // jLabel1.setHorizontalAlignment(SwingConstants.LEFT); jLabel1.setForeground(new Color(0, 0, 255)); jLabel1.setText("username:"); // // jLabel2 // jLabel2.setHorizontalAlignment(SwingConstants.LEFT); jLabel2.setForeground(new Color(0, 0, 255)); jLabel2.setText("password:"); // // jTextField1 // jTextField1.setForeground(new Color(0, 0, 255)); jTextField1.setSelectedTextColor(new Color(0, 0, 255)); jTextField1.setToolTipText("Enter your username"); jTextField1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ jTextField1_actionPerformed(e); } }); // // jPasswordField1 // jPasswordField1.setForeground(new Color(0, 0, 255)); jPasswordField1.setToolTipText("Enter your password"); jPasswordField1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ jPasswordField1_actionPerformed(e); } }); // // jButton1 // jButton1.setBackground(new Color(204, 204, 204)); jButton1.setForeground(new Color(0, 0, 255)); jButton1.setText("Login"); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ jButton1_actionPerformed(e); } }); // // contentPane // contentPane.setLayout(null); contentPane.setBorder(BorderFactory.createEtchedBorder()); contentPane.setBackground(new Color(204, 204, 204)); addComponent(contentPane, jLabel1, 5,10,106,18); addComponent(contentPane, jLabel2, 5,47,97,18); addComponent(contentPane, jTextField1, 110,10,183,22); addComponent(contentPane, jPasswordField1, 110,45,183,22); addComponent(contentPane, jButton1, 150,75,83,28); // // login // this.setTitle("Login To Members Area"); this.setLocation(new Point(76, 182)); this.setSize(new Dimension(335, 141)); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.setResizable(false); } /** Add Component Without a Layout Manager (Absolute Positioning) */ private void addComponent(Container container,Component c,int x,int y,int width,int height){ c.setBounds(x,y,width,height); container.add(c); } private void jTextField1_actionPerformed(ActionEvent e){ } private void jPasswordField1_actionPerformed(ActionEvent e){ } private void jButton1_actionPerformed(ActionEvent e){ System.out.println("\njButton1_actionPerformed(ActionEvent e) called."); String username = new String(jTextField1.getText()); String password = new String(jPasswordField1.getText()); if(username.equals("") || password.equals("")){// If password and username is empty > Do this >>> jButton1.setEnabled(false); JLabel errorFields = new JLabel("<HTML><FONT COLOR = Blue>You must enter a username and password to login.</FONT></HTML>"); JOptionPane.showMessageDialog(null,errorFields); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); this.setVisible(true); } else{ JLabel optionLabel = new JLabel("<HTML><FONT COLOR = Blue>You entered</FONT><FONT COLOR = RED> <B>"+username+"</B></FONT> <FONT COLOR = Blue>as your username.<BR> Is this correct?</FONT></HTML>"); int confirm =JOptionPane.showConfirmDialog(null,optionLabel); switch(confirm){ // Switch > Case case JOptionPane.YES_OPTION: // Attempt to Login user jButton1.setEnabled(false); // Set button enable to false to prevent 2 login attempts break; case JOptionPane.NO_OPTION: // No Case.(Go back. Set text to 0) jButton1.setEnabled(false); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); break; case JOptionPane.CANCEL_OPTION: // Cancel Case.(Go back. Set text to 0) jButton1.setEnabled(false); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); break; } // End Switch > Case } } public static void main(String[] args){ JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try{ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); }catch (Exception ex){ System.out.println("Failed loading L&F: "); System.out.println(ex); } new login(); }; } my connectDb class : public class Connectdb { private static Connection connect; private static String url ="jdbc:sqlite:data.db"; private static Statement st; private static ResultSet rs; /** * Constructeur privé d'une connection à la bd unique */ private ConnectionBd(){ try { Class.forName("org.sqlite.JDBC"); connect = DriverManager.getConnection(url); } catch (ClassNotFoundException ex) { Logger.getLogger(ex.getName()).log(Level.SEVERE, null, ex); } catch (SQLException e) { System.exit(e.getErrorCode()); } } public static Connection getInstance(){ if(connect == null){ new Connectdb(); }else{ } return connect; } /** * @return */ public static void initTable(String query){ try { Statement state = getInstance().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet res = state.executeQuery(query); res.close(); state.close(); } catch (SQLException e) { JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR ! ", JOptionPane.ERROR_MESSAGE); } }

    Read the article

  • add JButton into frame with JTable

    - by Edan
    hello, I would like to know how to put a button inside a frame that contain JTable inside. (The button should not be inside a cell, but after the table ends) Here is the example code I wrote so far: class SimpleTableExample extends JFrame { // Instance attributes used in this example private JPanel topPanel; private JTable table; private JScrollPane scrollPane; private JButton update_Button; // Constructor of main frame public SimpleTableExample() { // Set the frame characteristics setTitle("Add new item" ); setSize(300, 200); setBackground( Color.gray ); // Create a panel to hold all other components topPanel = new JPanel(); topPanel.setLayout( new BorderLayout() ); getContentPane().add( topPanel ); // Create columns names String columnNames[] = {"Item Description", "Item Type", "Item Price"}; // Create some data String dataValues[][] = {{ "0", "Entree", "0" }}; // Create a new table instance table = new JTable( dataValues, columnNames ); //////////////////////////// JComboBox item_Type_Combobox = new JComboBox(); item_Type_Combobox = new JComboBox(item_Type.values()); TableColumn column = table.getColumnModel().getColumn(1); column.setCellEditor(new DefaultCellEditor(item_Type_Combobox)); //////////////////////////// // Add the table to a scrolling pane scrollPane = new JScrollPane( table ); topPanel.add( scrollPane, BorderLayout.CENTER ); } } How do I add button after the table I created? thanks in advance

    Read the article

  • Java CountDownLatch used to wait for JFrame to dispose

    - by Brian
    I have referenced this previous question as well as other sources, but cannot get CountDownLatch to work correctly. Background: mainFrame creates new Frame called dataEntryFrame. When dataEntryFrame "Submit" button is clicked, record added to database and dataEntryFrame disposed. At this point, mainFrame should clear and reload a jList that shows all records. Issue: When dataEntryFrame loads, java freezes, dataEntryFrame components never load. I cannot get past this part... then, in the DataEntryFrame, CountDownLatch should only decrements after the submit button is clicked, successfully adds a record to a database table, and disposes itself. Or when the user clicks cancel... Code: From MainFrame CountDownLatch dataEntryDone = new CountDownLatch(1); DataEntryFrame f = new DataEntryFrame(dataEntryDone); Thread newThread = new Thread(f); newThread.start(); dataEntryDone.await(); Code: From DataEntryFrame public void run(){ initComponents(); loadOtherData(); this.setVisible(true); } void submit(){ addRecord(); this.dispose() dataEntryDone.countDown(); }

    Read the article

  • "Change" panel on jframe

    - by bog
    I have 2 panels, the first one is the menu, and the second is the application main panel. Firstly the menu panel shows up, than i need to switch to the other panel if a specific button is pressed on the menu (the menu is hidden but the app returns to it after running is completed). && i need to resize the frame too if it's possible. can i do this somehow?

    Read the article

  • Changing JTextArea to JScrollPane Causes it to not be visible

    - by user1806716
    I am having an issue with JScrollPanes and JTextArea objects and getting them to work together. If I just add a JTextArea to my JPanel, it works fine and shows up where I tell it to. However, if I change the contentPane.add(textArea) to contentPane.add(new JScrollPane(textArea)), the textArea is not longer visible and there is no sign of the textarea either. Here is my code: public docToolGUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 611, 487); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); textField = new JTextField(); textField.setBounds(253, 323, 86, 20); contentPane.add(textField); textField.setColumns(10); JLabel lblEnterRootDirectory = new JLabel("Enter Root Directory"); lblEnterRootDirectory.setBounds(253, 293, 127, 20); contentPane.add(lblEnterRootDirectory); JButton btnGo = new JButton("Go"); btnGo.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { new ToolWorker().execute(); } }); btnGo.setBounds(253, 361, 89, 23); contentPane.add(btnGo); textArea = new JTextArea(); textArea.setWrapStyleWord(true); textArea.setEditable(false); textArea.setBounds(25, 11, 560, 276); contentPane.add(new JScrollPane(textArea)); }

    Read the article

  • JSplitPane overlaps JButtons in BorderLayout, but does not when layout is null

    - by thaweatherman
    So I'm having another issue..... I'm currently using a BorderLayout in my GUI so that when I resize my jframe, all of the internal components resize with it. I couldn't get any other layout to work with how I want the GUI to look while providing this resizing capability. At the top I have a JMenuBar, and below it I have a bunch of buttons. Below that I am supposed to have a JSplitPane, and it is there. However, the buttons seemed to be contained within the JSplitPane, which is not my intention. So when anything happens within the splitpane, the buttons disappear until I move my mouse over them again. When I set my layout to null everything works great except I lose the resizing capability, which is not good. Tried posting images but it wont let me since my rep isnt at 10 yet :( Any suggestions? I've tried putting the buttons into a JPanel then adding the jpanel but the splitpane overlaps with that. Same with a JToolBar. The order in which I add my items is: 1) the menu bar setJMenuBar(menuBar) 2) the buttons getContentPane().add(btnZoomIn) etc. 3) the split pane getContentPane().add(splitPane) then the rest of the things you see after that

    Read the article

  • Printing a JFrame and its components

    - by Alex Terreaux
    I have been working in a big program and one of its functionalities should be to print the contents of the main window. I checked the API and found this example: http://docs.oracle.com/javase/tutorial/2d/printing/gui.html it was very helpful, I tried to use that code in my program by placing this inside the actionperformed method of my print button: PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException ex) { /* The job did not successfully complete */ } } If I click the print button, I get a printer dialog and when I tell it to print, it just prints a blank document. I know the above code is not all I need, as I've seen in the API's examples there is a print() method, but apparently they never call it, so it is pretty confusing. I've tried calling and using it many times, but with no success. Also, I think that when I finally get it to print, my window will need to be printed in the landscape orientation, it even may need some scaling. Any ideas on how to do that? I would like any useful help to help me implement this code successfully. I know I should be able to do it by myself just by checking the documentation (I've tried for almost 2 days now) but I can't get it to work. I've learned all the programming I know through the internet. Any help will be greatly appreciated.

    Read the article

  • How do I make a Java gave without a JFrame?

    - by kullalok
    I am working on an arcade-like game, and so far, I have been using JFrame. All the action occurs in the JFrame basically. However, I've noticed that a lot of games that you install on a computer don't have a frame. When you play them on Windows, the game covers the entire screen (the start bar disappears and you can't access any other application on your computer). I'd like to do that for my game. Is it possible to do so with Java? If so, how would I do this?

    Read the article

  • Cannot find Symbol = new

    - by Nick G.
    Java is complaining! cannot find symbol symbol : constructor Bar() location: class Bar JPanel panel = new Bar(); ^ QUESTION: Why am I getting this error?...everything seems to be correct. this is the coding: public class JFrameWithPanel { public static void main(String[] args) { JPanel panel = new Bar(); } } Bar( ) is public class Bar extends JPanel { public Bar(final JFrame frame) { super(new BorderLayout()); String[] tests = { "A+ Certification", "Network+ Certification", "Security+ Certification", "CIT Full Test Package" }; JComboBox comboBox = new JComboBox(tests); TextArea text = new TextArea(5, 10); add(new JLabel("Welcome to the CIT Test Program ")); add(new JLabel("Please select which Test Package from the list below.")); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu editMenu = new JMenu("Edit"); JMenu helpMenu = new JMenu("Help"); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); JMenuItem newMenu = new JMenuItem("New (Ctrl+N)"); JMenuItem openMenu = new JMenuItem("Open (Ctrl+O)"); JMenuItem saveMenu = new JMenuItem("Save (Ctrl+S)"); JMenuItem exitMenu = new JMenuItem("Exit (Ctrl+W)"); JMenuItem cutMenu = new JMenuItem("Cut (Ctrl+X)"); JMenuItem copyMenu = new JMenuItem("Copy (Ctrl+C)"); JMenuItem pasteMenu = new JMenuItem("Paste (Ctrl+V)"); JMenuItem infoMenu = new JMenuItem("Help (Ctrl+H)"); fileMenu.add(newMenu); fileMenu.add(openMenu); fileMenu.add(saveMenu); fileMenu.add(exitMenu); editMenu.add(cutMenu); editMenu.add(copyMenu); editMenu.add(pasteMenu); helpMenu.add(infoMenu); this.add(comboBox, BorderLayout.NORTH); this.add(text, BorderLayout.SOUTH); frame.setJMenuBar(menuBar); add(new JButton("Select") { { addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); JOptionPane.showMessageDialog(frame, "IT WORKS!"); } }); } }); } }

    Read the article

  • How do I get my character to move after adding to JFrame?

    - by A.K.
    So this is kind of a follow up on my other JPanel question that got resolved by playing around with the Layout... Now my MouseListener allows me to add a new Board(); object from its class, which is the actual game map and animator itself. But since my Board() takes Key Events from a Player Object inside the Board Class, I'm not sure if they are being started. Here's my Frame Class, where SideScroller S is the player object: package OurPackage; //Made By A.K. 5/24/12 //Contains Frame. import java.awt.BorderLayout; import java.awt.Button; import java.awt.CardLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Image; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.*; import javax.swing.plaf.basic.BasicOptionPaneUI.ButtonActionListener; public class Frame implements MouseListener { public static boolean StartGame = false; JFrame frm = new JFrame("Action-Packed Jack"); ImageIcon img = new ImageIcon(getClass().getResource("/Images/ActionJackTitle.png")); ImageIcon StartImg = new ImageIcon(getClass().getResource("/Images/JackStart.png")); public Image Title; JLabel TitleL = new JLabel(img); public JPanel TitlePane = new JPanel(); public JPanel BoardPane = new JPanel(); JPanel cards; JButton StartB = new JButton(StartImg); Board nBoard = new Board(); static Sound nSound; public Frame() { frm.setLayout(new GridBagLayout()); cards = new JPanel(new CardLayout()); nSound = new Sound("/Sounds/BunchaJazz.wav"); TitleL.setPreferredSize(new Dimension(970, 420)); frm.add(TitleL); frm.add(cards); cards.setSize(new Dimension(150, 45)); cards.setLayout(new GridBagLayout ()); cards.add(StartB); StartB.addMouseListener(this); StartB.setPreferredSize(new Dimension(150, 45)); frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.setSize(1200, 420); frm.setVisible(true); frm.setResizable(false); frm.setLocationRelativeTo(null); frm.pack(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new Frame(); } }); } public void mouseClicked(MouseEvent e) { nSound.play(); StartB.setContentAreaFilled(false); cards.remove(StartB); frm.remove(TitleL); frm.remove(cards); frm.setLayout(new GridLayout(1, 1)); frm.add(nBoard); //Add Game "Tiles" Or Content. x = 1200 nBoard.setPreferredSize(new Dimension(1200, 420)); cards.revalidate(); frm.validate(); } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } }

    Read the article

  • How can I Implement KeyListeners/ActionListeners into the JFrame?

    - by A.K.
    I'll get to the point: I have a player in my game that you control with the keyboard yet the key methods in the player class and ActionListener w/ KeyAdapter in the Board class don't seem to fire. So far I've tried adding these key methods into the JFrame, doesn't seem to let me move him even though other objects that I have (enemies) can move fine. Here's part of the JFrame class with the event listeners: frm.addKeyListener(KeyBoardListener); public void mouseClicked(MouseEvent e) { nSound.play(); StartB.setContentAreaFilled(false); cards.remove(StartB); frm.remove(TitleL); frm.remove(cards); frm.setLayout(new GridLayout(1, 1)); frm.add(nBoard); //Add Game "Tiles" Or Content. x = 1200 nBoard.setPreferredSize(new Dimension(1200, 420)); cards.revalidate(); frm.validate(); } public KeyListener KeyBoardListener = new KeyListener() { @Override public void keyPressed(KeyEvent args0) { int key = args0.getKeyCode(); if(key == KeyEvent.VK_LEFT) { nBoard.S.vx = -4; } if(key == KeyEvent.VK_RIGHT) { nBoard.S.vx = 4; } if(key == KeyEvent.VK_UP) { nBoard.S.vy = -4; } if(key == KeyEvent.VK_DOWN) { nBoard.S.vy = 4; } if(key == KeyEvent.VK_SPACE) { nBoard.S.fire(); } } @Override public void keyReleased(KeyEvent args0) { int key = args0.getKeyCode(); if(key == KeyEvent.VK_LEFT) { nBoard.S.vx = 0; } if(key == KeyEvent.VK_RIGHT) { nBoard.S.vx = 0; } if(key == KeyEvent.VK_UP) { nBoard.S.vy = 0; } if(key == KeyEvent.VK_DOWN) { nBoard.S.vy = 0; } } @Override public void keyTyped(KeyEvent args0) { // TODO Auto-generated method stub } };

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >