jScrollPane setVisible doesn't work
java, jscrollpane, jtable, swing
Solution
After `pane.setVisible(true);` add the following:
getContentPane().validate();
getContentPane().repaint();
Problem
I have a show button to show a `JTable` on click but the table is not visible. Note: when I remove the `JScrollPane` the code works properly but the header of the table is not shown, so any help please to make this code work properly without removing the `JScrollPane` ``` import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class Training extends JFrame { public Training() { getContentPane().setLayout(new FlowLayout()); JTable table = new JTable(); table.setModel(new DefaultTableModel(new Object[][] { { "joe", "joe" }, { "mickel", "mickel" }, }, new String[] { "LastName", "FirstName" })); final JScrollPane pane = new JScrollPane(table); pane.setVisible(false); getContentPane().add(pane); JButton btn = new JButton("show"); add(btn); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub pane.setVisible(true); } }); } public static void main(String[] args) { Training app = new Training(); app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); app.setSize(600, 600); app.setVisible(true); } } ```