有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如果设置为BasicToolBarUI,java JToolbar不会显示在Ubuntu上

我已经决定用JToolBar定制自己的用户界面 子类化BasicTolbarui,作为我的Swing程序的一部分

它在OSX(10.6)和Windows(7)下工作得很好,但是 说到Linux,就会出现以下问题:

如果回转组件

  • 使用SystemLookAndFeel(显示的是Java LAF)
  • 使用UIBasicToolBarUI(简化问题。这样做已经不起作用了)
  • 在Linux(Ubuntu 10.10)下运行

整个JToolBar不再出现

有人能帮忙吗?如何让它再次出现在Linux上?提前谢谢你

(我已经完成了自定义UI,以便 让用户仍然能够将工具栏移动到其他边缘 ,但要防止它变为浮动状态。)

干杯,


我的SSCCE:

// Set the system look and feel:
try { 
 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
 e.printStackTrace();
}

// Create frame
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(200, 100));

// Create toolbar
JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL);
toolbar.add(new JButton("Foo"));
// With this line toolbar doesn't appear any more (only) on Linux.
toolbar.setUI(new BasicToolBarUI());

// Show UI
panel.add(toolbar);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);

共 (1) 个答案

  1. # 1 楼答案

    您可能看不到它,因为您没有添加任何内容(操作、按钮等)。空工具栏的高度通常为1-2像素

    更新: 从我看到的BasicTolbarui可以看出,它实际上什么都没做——你必须自己进行尺寸计算和绘制,才能得到正确的结果