Reputation: 1289
I have a JTable in a swing application. I wrote a quick and dirty un-dock operation where the JTable is removed from its default parent and gets added to a seperate JFrame. When the JTable is undocked and placed on a seperate JPane it is REALLY slow at moving around in the JTable... as soon as I dock it back into its original place, it's back to acting normal again... below is the code for the undocker.. any ideas? thank you
JTABLE UNDOCKER
public class MatrixWindowUndocker implements ActionListener{
private static final Logger logger = Logger.getLogger(
MatrixWindowUndocker.class.getName());
MatrixVerifier mv;
public MatrixWindowUndocker(MatrixVerifier mv)
{
this.mv = mv;
}
public void actionPerformed(ActionEvent e)
{
undockMatrixPanel(mv);
}
private static void undockMatrixPanel(MatrixVerifier mv)
{
JFrame undockedFrame = mv.undockedWindowFrame;
undockedFrame.setDefaultCloseOperation(
WindowConstants.DO_NOTHING_ON_CLOSE);
locateFrame(undockedFrame);
mv.mainMatrixTablePanel.remove(mv.mainMatrixTableScrollPane);
undockedFrame.setLayout(new BorderLayout());
undockedFrame.add(mv.mainMatrixTableScrollPane);
mv.pdfAndMetadata_JPanel.remove(mv.table_pdf_splitter);
mv.pdfAndMetadata_JPanel.add(mv.pdfDrawCanvasPanel);
mv.pack();
mv.setExtendedState(JFrame.MAXIMIZED_BOTH);
undockedFrame.pack();
undockedFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
mv.undockedFrame = undockedFrame;
undockedFrame.setVisible(true);
}
private static void locateFrame(JFrame frame)
{
GraphicsConfiguration gc = null;
GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
logger.debug("gds.length: " + gds.length);
if (gds != null && gds.length > 1)
{
gc = gds[1].getDefaultConfiguration();
}
else
{
gc = gds[0].getDefaultConfiguration();
}
frame.setLocation(10 + gc.getBounds().x, 10 + gc.getBounds().y);
}
}
JTABLE DOCKER
public class MatrixWindowDocker implements ActionListener
{
MatrixVerifier mv;
public void setMv(MatrixVerifier mv)
{
this.mv = mv;
}
public MatrixWindowDocker(MatrixVerifier mv)
{
this.mv = mv;
}
/**
* Main action method.
* @param e
*/
public void actionPerformed(ActionEvent e)
{
dockMatrixPanel(mv);
}
private static void dockMatrixPanel(MatrixVerifier mv)
{
if (mv.undockedFrame != null)
{
mv.undockedFrame.dispose();
mv.pdfAndMetadata_JPanel.setAlignmentX(0.8F);
mv.pdfAndMetadata_JPanel.setMinimumSize(new java.awt.Dimension(550,
0));
mv.pdfAndMetadata_JPanel.setPreferredSize(new java.awt.Dimension(800,
0));
mv.pdfAndMetadata_JPanel.setLayout(new java.awt.BorderLayout());
mv.table_pdf_splitter.setDividerLocation(.60);
mv.table_pdf_splitter.setDividerSize(2);
mv.table_pdf_splitter.setResizeWeight(0.3);
mv.table_pdf_splitter.setDividerLocation(0.50);
mv.pdfAndMetadata_JPanel.add(mv.table_pdf_splitter,
java.awt.BorderLayout.CENTER);
mv.table_pdf_splitter.setLeftComponent(mv.pdfDrawCanvasPanel);
mv.mainMatrixTablePanel.setLayout(new java.awt.BorderLayout());
mv.mainMatrixTableScrollPane.setViewportView(mv.metadataTable_JTable);
mv.mainMatrixTablePanel.add(mv.mainMatrixTableScrollPane,
java.awt.BorderLayout.CENTER);
mv.table_pdf_splitter.setRightComponent(mv.mainMatrixTablePanel);
}
}
}
Upvotes: 1
Views: 727
Reputation: 182878
There is a rudimentary profiler included in the JDK from JDK 1.6, I think called jvisualvm. You might try using it to see what's going on. Even better would be a real profiler, but the only good ones are for-pay although some have 30 day free trials.
Upvotes: 1