JTable很慢

时间:2010-08-11 17:41:53

标签: java user-interface swing jtable

我在swing应用程序中有一个JTable。我编写了一个快速而脏的非停靠操作,其中JTable从其默认父项中删除,并添加到单独的JFrame中。当JTable脱离并放置在单独的JPane上时,它在JTable中移动真的很慢......一旦我将它停靠回原来的位置,它就会恢复正常状态......下面是代码解开.. 有任何想法吗? 谢谢

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);
}

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);
    }
}

1 个答案:

答案 0 :(得分:1)

JDK 1.6中的JDK中包含了一个基本的分析器,我认为是jvisualvm。您可以尝试使用它来查看正在发生的事情。更好的是一个真正的探测器,但唯一好的是付费,虽然有些有30天免费试用。