java - 隐形JFrame/JTable 快多少?

标签 java performance swing jtable jframe

我有一个 Swing 应用程序。带有许多包含大型 JTable 的内部框架的 jframe。 这些 jtable 会不断更新,因此需要进行大量的重新绘制。

在某些情况下,我可以简单地保持 JFrame 不可见。 (frame.setVisible(假))

我想知道是否有人知道我是否会在性能方面有所收获 (重要或不重要的事情)

比如 50% 的 yield ,否则你只会获得 2% 的 yield ...

也许还有一些关于预期结果的解释。

谢谢

附: 另一种改写问题的方式是: Swing 组件是否足够聪明,不会在不可见的情况下自行重绘/回流???

最佳答案

看看Swing Painting Guidelines其中有一些关于绘画效率的有用技巧。例如:

On components with complex output, repaint() should be invoked with arguments which define only the rectangle that needs updating, rather than the no-arg version, which causes the entire component to be repainted.

Components which render complex output should make smart use of the clip rectangle to narrow the drawing operations to those which intersect with the clip area.

证明不可见组件没有被绘制也很容易。以下代码隐藏面板并在调用 Paint 时打印出来。

public static void main(String args[]) throws Exception {
    JFrame f = new JFrame();
    final JPanel p = new JPanel(){
        public void paint(Graphics g){
            super.paint(g);
            System.out.println("IN PAINT");
            g.fillRect(10, 10, 20, 20);
        }
    };
    f.setLayout(new BorderLayout());
    f.add(p, BorderLayout.CENTER);

    JButton b = new JButton("OK");
    b.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("PRESSED");
            p.setVisible(!p.isVisible());
        }
    });
    f.add(b, BorderLayout.SOUTH);
    f.setSize(100,100);
    f.setVisible(true);
}

关于java - 隐形JFrame/JTable 快多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4593267/

相关文章:

java - JTable 彩色行标题出现在表格未出现的位置

java - 使用 RPC 服务的 GWT.create 的目的是什么?

java - 这些字符串操作在 Java 和 Python 中是否等效?

javascript - 有没有一种方法可以利用在JavaScript工厂函数中使用原型(prototype)方法的性能优势?

mongodb - 如何从 MongoDB 中删除数据而不使其停止运行?

Java 日期方法?类? joptionpane/输出/显示数据库中数组列表中的对象?

java - 如何解决Java LinkageError异常?

java - 带有空指针异常的Android setonclicklistener

java - 调试 Apache Tomcat

java - Swing 到 SWT 转换 : which disadvantages?