How can I make my JTable appear on button click?

bilal fofo

New Member
The following code works, but only after the Display Values and the resize button is pushed. It does not appear until after I push both the Display Values and the resize button is pushed. How do I make it appear when only the Display Values button is pushed?\[code\] public class myClass extends JFrame{ String[] colNames = {"Item Name", "Department", "Original Price", "Sales Price"}; Object[][] input = { {"Kathy", "Smith", new Double(10), new Integer(5)}, {"John", "Doe", new Double(10), new Integer(3)}, {"Sue", "Black", new Double(10), new Integer(2)}, {"Jane", "White", new Double(10), new Integer(20)}, {"Joe", "Brown", new Double(10), new Integer(10)} }; //display values JButton buttonDisplay = new JButton(); buttonDisplay.setText("Display Values"); container.add(buttonDisplay); buttonDisplay.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { JTable jt = new JTable( input, colNames ); JScrollPane pane = new JScrollPane( jt ); jt.setPreferredScrollableViewportSize( new Dimension(200,200)); pane.add(jt); container.add( pane ); container.add(jt); /*Must use a JTextBox or JTable to display all the stored values for: * * Item name Department Original price Sale price */ } });\[/code\]
 
Back
Top