本文整理了Java中javax.swing.JMenuItem.setPreferredSize()
方法的一些代码示例,展示了JMenuItem.setPreferredSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuItem.setPreferredSize()
方法的具体详情如下:
包路径:javax.swing.JMenuItem
类名称:JMenuItem
方法名:setPreferredSize
暂无
代码示例来源:origin: stackoverflow.com
private JMenuItem createColoredSeparator(Color color){
JMenuItem separator = new JMenuItem();
separator.setPreferredSize(new Dimension(5,5));
separator.setBackground(color);
separator.setEnabled(false); //make the item unclickable so menu doesn't close
return separator;
}
代码示例来源:origin: stackoverflow.com
JMenuItem item = new JMenuItem();
item.setPreferredSize(new Dimension(200, item.getPreferredSize().height));
代码示例来源:origin: stackoverflow.com
JMenu menu = new JMenu("Menu");
JMenuItem item = new JMenuItem("Add");
item.add(new JButton("SOMETHING A BIT WORDY"));
item.setLayout(new FlowLayout()); // set FlowLayout for item
item.setPreferredSize(new Dimension(200, 100)); // hard code implementation :-(
menu.add(item);
// ...
JMenuBar menuBar = new JMenuBar();
menuBar.add(menu);
JFrame frame = new JFrame();
frame.setJMenuBar(menuBar);
// ...
frame.pack();
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
private JMenuItem createColoredSeparator(Color color){
JMenuItem separator = new JMenuItem();
separator.setPreferredSize(new Dimension(50,50)); //Increased to highlight whats happening
//Imitate the default raised border
Border raisedBorder = BorderFactory.createBevelBorder(BevelBorder.RAISED,
UIManager.getColor("MenuItem.background"),UIManager.getColor("MenuItem.background").darker());
//Merge the borders with the raised border applied outside of the border concealing part of the background
separator.setBorder(new CompoundBorder(
raisedBorder, BorderFactory.createLineBorder(UIManager.getColor("MenuItem.background"), 8)));
separator.setBackground(color);
separator.setEnabled(false); //make the item un-clickable so menu doesn't close
return separator;
}
代码示例来源:origin: stackoverflow.com
private JMenuItem newItem(String text, String iconPath) {
JMenuItem myMenuItem;
if (iconPath == null || iconPath.isEmpty()) {
myMenuItem = new JMenuItem(text);
myMenuItem.setPreferredSize(new Dimension(myMenuItem.getFontMetrics(myMenuItem.getFont()).stringWidth(text), 20));
} else {
ImageIcon icon = new ImageIcon(iconPath);
myMenuItem = new JMenuItem(text, icon);
myMenuItem.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
}
return myMenuItem;
}
代码示例来源:origin: stackoverflow.com
private JMenuItem newItem(String text, String iconPath) {
JMenuItem myMenuItem;
ImageIcon icon= null;
int iconPixels = 0;
if (iconPath == null || iconPath.isEmpty()) {
myMenuItem = new JMenuItem(text);
}
else {
icon = new ImageIcon(iconPath);
myMenuItem = new JMenuItem(text, icon);
iconPixels = icon.getIconWidth();
}
FontMetrics fontM = myMenuItem.getFontMetrics(new Font("Default", Font.PLAIN, 12));
int stringPixels = fontM.stringWidth(text);
int newWidth = stringPixels + iconPixels;
newWidth = newWidth < Menu.MINWIDTH ? Menu.MINWIDTH : newWidth;
newWidth = newWidth > Menu.MAXWIDTH ? Menu.MAXWIDTH : newWidth;
myMenuItem.setPreferredSize(new Dimension(newWidth, 20));
System.out.println(text + " - " + newWidth);
return myMenuItem;
}
代码示例来源:origin: MrCrayfish/ModelCreator
item.add(label);
Dimension size = new Dimension((int) Math.ceil(item.getPreferredSize().getWidth() + label.getPreferredSize().getWidth()) + 10, 20);
item.setPreferredSize(size);
代码示例来源:origin: igvteam/igv
Dimension size = new Dimension();
size.setSize(w, h+8);
item.setPreferredSize(size);
代码示例来源:origin: org.apache.oodt/oodt-profile
newFileMenuItem.setPreferredSize(new java.awt.Dimension(28,16));
newFileMenuItem.setBounds(new java.awt.Rectangle(5,5,28,16));
jMenu3.add(newFileMenuItem);
cutMenuItem.setPreferredSize(new java.awt.Dimension(27,16));
cutMenuItem.setBounds(new java.awt.Rectangle(5,5,27,16));
jMenu4.add(cutMenuItem);
helpMenuItem.setPreferredSize(new java.awt.Dimension(31,16));
helpMenuItem.setBounds(new java.awt.Rectangle(5,5,31,16));
jMenu5.add(helpMenuItem);
内容来源于网络,如有侵权,请联系作者删除!