如果设置为 BasicToolBarUI,JToolbar 在 Ubuntu 上不会显示
我决定拥有自己的 JToolBar
自定义 UI 子类化 BasicToolBarUI,作为我的 Swing
程序的一部分。
它在 OS X (10.6) 和 Windows (7) 下运行良好,但是 当涉及到Linux时,会出现问题:
如果swing组件
- 使用
SystemLookAndFeel
(使用Java LAF则显示) - 使用UI
BasicToolBarUI
(为了简化问题。有了这个它就可以了)已经不起作用) - 在 Linux (Ubuntu 10.10) 下运行时
整个 JToolBar
不再出现。
有人可以帮忙吗?如何让它再次出现在Linux上?先感谢您。
(我已经完成了自定义用户界面,以便 让用户仍然能够将工具栏移动到其他边缘 窗口的,但防止它进入浮动状态。)
干杯,
说
我的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);
I've decided to have my own custom UI of JToolBar
by
subclassing BasicToolBarUI, as part of my Swing
program.
It works great under OS X (10.6) and Windows (7), but
when it comes to Linux, problem occurs:
If the swing component is
- Using
SystemLookAndFeel
(With Java LAF it is shown) - Using UI
BasicToolBarUI
(To simplify the problem. With this it already doesn't work) - running under Linux (Ubuntu 10.10)
the whole JToolBar
doesn't appear anymore.
Can anyone give a hand on this? How to make it appear again on Linux? Thank you in advance.
(I've done the custom UI in order to
let user still able to move the toolbar to other edges
of the window, but prevent it from going to floating state.)
Cheers,
Shuo
My 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能看不到它,因为您没有向其中添加任何内容(操作、按钮等)。空工具栏的高度通常为 1-2 像素。
更新:
据我所知,通过查看 BasicToolBarUI 它并没有真正做任何事情 - 你必须实现尺寸计算并自己绘制才能获得正确的结果
You may not see it because you haven't added anything to it (actions, buttons etc). Empty toolbar usually has height of 1-2 pixels.
UPDATE:
From what I can tell by looking at BasicToolBarUI it doesn't really do anything - you have to implement size calculations and painting yourself to get proper results