![](/img/trans.png)
[英]implementing UI for relationship between Entities of a database via Swing-java
[英]One menu at the right swing-java
假設我有5個菜單(文件,編輯,視圖,窗口和幫助),現在我想將help
放置在框架的右側,並將其余的保留在左側,像這樣
+----------------------------------------------------------------------------+
| File | Edit | View | Window Help |
+----------------------------------------------------------------------------+
秋千有可能嗎? 暗含菜單? 或一些hack /技巧?
help
不應是真正的Menu
對象,而應是任何可單擊的對象( Jlabel
,...)
您需要做的就是在需要間隙的位置向JMenuBar添加水平膠水。
menuBar.add(Box.createHorizontalGlue());
例如,
import java.awt.Dimension;
import javax.swing.*;
public class MenuEg {
private static void createAndShowGui() {
JMenuBar menuBar = new JMenuBar();
menuBar.add(new JMenu("File"));
menuBar.add(new JMenu("Edit"));
menuBar.add(new JMenu("View"));
menuBar.add(new JMenu("Window"));
menuBar.add(Box.createHorizontalGlue());
menuBar.add(new JMenu("Help"));
JFrame frame = new JFrame("MenuEg");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setJMenuBar(menuBar);
frame.getContentPane().add(Box.createRigidArea(new Dimension(600, 400)));
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.