Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Reason for disappearance of JScrollPane from the <code>ActualFrame</code> is that: You are adding the same instance of <code>pane</code> in <code>PreviewFrame</code>. So the actual container of the <code>pane</code> is now <code>PreviewFrame</code> instead of <code>ActualFrame</code>. When you maximize or resize the <code>ActualFrame</code>,it repaint its child components. Since the <code>pane</code> now no longer belongs to the <code>ActualFrame</code> it does not show the <code>pane</code> now.<P> The best way to avoid this situation is to create a seperate <code>JTabel</code> instance first, instead of passing anonymous <code>JTable</code> class object within the constructor of <code>JScrollPane</code> while creating the object <code>pane</code> . Get the <code>TableModel</code> and <code>TableColumnModel</code> of that <code>JTable</code> instance. In <code>previewFrame</code> add a new instance of <code>JScrollPane</code> that will contain the new instance of <code>JTable</code> with same <code>TableModel</code> and <code>TableColumnModel</code> objects. The Code would look something like this:</p> <pre><code>final JTable table = new JTable(data,columns); JScrollPane pane = new JScrollPane(table); ActualFrame.add(pane); ActualFrame.add(PrintPreviewBtn); PrintPreviewBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFrame previewFrame = new JFrame("Preview"); javax.swing.table.TableModel tabModel = table.getModel(); javax.swing.table.TableColumnModel colModel = table.getColumnModel(); JScrollPane previewPane = new JScrollPane(new JTable(tabModel,colModel)); previewFrame.getContentPane().add(previewPane, BorderLayout.CENTER); previewFrame.pack();previewFrame.setVisible(true); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload