【问题标题】:After losing the focus on the JPanel screen in swing, screen don't show the content在摇摆的JPanel屏幕上失去焦点后,屏幕不显示内容
【发布时间】:2012-05-04 16:18:19
【问题描述】:

我使用 JTabbedPane 和 JPanel 在一个选项卡上显示 JTable,在另一个选项卡上显示文本、下拉菜单和 jbutton。

第一次工作正常,但如果我最小化或切换屏幕到其他应用程序并返回到我的应用程序,它会正确显示数据,但 JTabbedPane 中的选项卡更改存在严重问题。现在选项卡屏幕变为蓝色并且不显示数据。(我希望数据在那里,但它不是重新绘制或刷新完整的窗口)。

现在在蓝屏的情况下,我执行相同的程序并更改 JTabbedPane 中的选项卡,它显示正确的数据。

我使用了重绘,但它不起作用。

需要帮助才能正确刷新窗口或选项卡。

【问题讨论】:

  • 请分享说明问题的SSCCE
  • 正如 Max 所说,SSCCE 是必需的。话虽如此,也许试试 revalidate()?

标签: java swing jpanel jtabbedpane


【解决方案1】:

确保您正在通过 de Event Dispatch Thread 对 Swing 组件进行所有修改(包括更改 de 模型中的数据或手动切换选项卡)。 Swing 允许开发人员忽略线程安全,但这会产生未定义的行为。

这是一个修改 JComboBox 模型内容的示例。

final DefaultComboBoxModel model = (DefaultComboBoxModel) comboBox.getModel();
EventQueue.invokeLater(new Runnable(){
    public void run(){
        // Add all Swing component modification code here..
        // The line of code below is but an example of what you could do
        model.addElement("String element");
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    相关资源
    最近更新 更多