本文整理了Java中javax.swing.JMenuItem.getIcon()
方法的一些代码示例,展示了JMenuItem.getIcon()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuItem.getIcon()
方法的具体详情如下:
包路径:javax.swing.JMenuItem
类名称:JMenuItem
方法名:getIcon
暂无
代码示例来源:origin: org.netbeans.api/org-openide-awt
for (int i = 0; i < items.length; i++) {
if (items[i] instanceof JMenuItem) {
if (((JMenuItem) items[i]).getIcon() != null) {
shouldAlign = true;
curItem = (JMenuItem) items[i];
if (curItem.getIcon() == null) {
curItem.setIcon(BLANK_ICON);
代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce
private static void alignCheck( JMenuItem item, Dimension size, Border border) {
Icon icon = item.getIcon();
if ( border != null) {
item.setBorder( border);
}
if ( icon != null && icon.getIconWidth() < size.width) {
item.setIconTextGap( item.getIconTextGap() + ((size.width - icon.getIconWidth())/2));
} else if ( icon == null) {
item.setIcon( new DummyIcon( size));
}
}
代码示例来源:origin: com.github.axet/desktop
public MenuMap(JMenuItem item) {
this.item = item;
if (item.getIcon() != null) {
Icon icon = item.getIcon();
hbm = convertMenuImage(icon);
}
}
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
Icon checkIcon,
Icon arrowIcon,
int defaultTextIconGap) {
JMenuItem b = (JMenuItem) c;
Icon icon = (Icon) b.getIcon();
if (icon == null) {
return new Dimension(22, 22);
}
return new Dimension(icon.getIconWidth() + 2, icon.getIconHeight() + 2);
}
@Override
代码示例来源:origin: com.eas.platypus/platypus-js-forms
@ScriptFunction(jsDoc = ICON_JSDOC)
@Override
public Icon getIcon() {
return super.getIcon();
}
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
public void paint(Graphics g, JComponent c) {
JMenuItem b = (JMenuItem) c;
// Paint background
paintBackground(g, b, selectionBackground);
// Paint the icon
//((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Icon icon = (Icon) b.getIcon();
if (icon != null) {
icon.paintIcon(b, g, 1, 1);
}
}
}
代码示例来源:origin: stackoverflow.com
for (int mi=0; mi<colors.length; mi++){
String pos = Character.toUpperCase(colors[mi].charAt(0)) + colors[mi].substring(1);
JMenuItem Jmi =new JMenuItem(pos);
Jmi.setIcon(new IconA(colors[mi]));
// workaround:
final Integer innerMi = new Integer(mi);
Jmi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem item = (JMenuItem) e.getSource();
IconA icon = (IconA) item.getIcon();
// HERE YOU USE THE FINAL innerMi variable and no errors!!!
Color kolorIkony = getColour(colors[innerMi]);
textArea.setForeground(kolorIkony);
}
});
mnForeground.add(Jmi);
}
}
代码示例来源:origin: com.jidesoft/jide-oss
private int[] getIconPaddings(JMenuItem b) {
int[] subFlags = new int[]{0, 0};
if (b != null && (b.getParent() instanceof JPopupMenu)) {
JPopupMenu parentMenu = (JPopupMenu) b.getParent();
for (MenuElement item : parentMenu.getSubElements()) {
if (item instanceof JCheckBoxMenuItem) {
subFlags[0] = 10;
}
if ((item instanceof JMenuItem) && ((JMenuItem) item).getIcon() != null) {
subFlags[1] = Math.max(subFlags[1], ((JMenuItem) item).getIcon().getIconWidth());
}
}
}
return subFlags;
}
代码示例来源:origin: chatty/chatty
public final void setAction(String key, Action action) {
JMenuItem item = menuItems.get(key);
// Preserve icon
Icon icon = item.getIcon();
item.setAction(action);
item.setIcon(icon);
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu
public Icon getIcon()
{
if(BuPreferences.BU.getBooleanProperty("icons.menu",true)||
(super.getText()==null))
return super.getIcon();
return null;
}
代码示例来源:origin: com.fifesoft.rtext/fife.common
@Override
public void paint(Graphics g, JComponent c) {
JMenuItem menuItem = (JMenuItem)c;
ButtonModel model = menuItem.getModel();
// Get color through UIManager in case of LnF change.
g.setColor(background);
Rectangle bounds = c.getBounds();
g.fillRect(0,0, bounds.width,bounds.height);
// Swatches are always enabled, so we only have to check
// whether or not they are armed.
if (model.isArmed()) {
g.setColor(armedSwatchSelectionRectColor);
g.drawRect(1,1, bounds.width-3,bounds.height-3);
}
Icon icon = menuItem.getIcon();
int x = (bounds.width-icon.getIconWidth())/2;
int y = (bounds.height-icon.getIconHeight())/2;
icon.paintIcon(menuItem, g, x,y);
}
代码示例来源:origin: fr.ifremer/isis-fish
/**
* Make new script, and select it on tree.
*/
public void newScript(ScriptUI view, MouseEvent event) {
JPopupMenu menu = new JPopupMenu();
// make a basic copy of already existing menu
JMenu oldMenu = view.getScriptNewMenu();
for (int i = 0; i < oldMenu.getItemCount(); i++) {
JMenuItem oldMenuItem = (JMenuItem)oldMenu.getMenuComponent(i);
JMenuItem miCopy = new JMenuItem();
miCopy.setText(oldMenuItem.getText());
miCopy.setIcon(oldMenuItem.getIcon());
for (ActionListener l : oldMenuItem.getActionListeners()) {
miCopy.addActionListener(l);
}
menu.add(miCopy);
}
menu.show((Component)event.getSource(), event.getX(), event.getY());
}
代码示例来源:origin: com.github.arnabk/pgslookandfeel
protected void installDefaults() {
super.installDefaults();
if (menuItem.getIcon() == null) {
menuItem.setIcon(PgsIconFactory.getEmptyIcon());
}
}
代码示例来源:origin: com.fifesoft.rtext/fife.common
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source instanceof JMenuItem) {
JMenuItem item = (JMenuItem)source;
Icon icon = item.getIcon();
// If it has an icon, it must be a swatch.
if (icon!=null) {
ColorIcon colorIcon = (ColorIcon)icon;
Color color = colorIcon.getColor();
RColorSwatchesButton.this.setColor(color);
}
// Otherwise, it is the "More colors..." menu item.
else {
e.setSource(RColorSwatchesButton.this);
super.actionPerformed(e);
}
}
}
代码示例来源:origin: com.jidesoft/jide-oss
protected void paintCheckBox(JMenuItem b, Graphics g, Icon checkIcon) {
ButtonModel model = b.getModel();
boolean isSelected = false;
if (b instanceof JCheckBoxMenuItem)
isSelected = b.isSelected();
else if (b instanceof JRadioButtonMenuItem)
isSelected = b.isSelected();
if (isSelected) {
if (model.isArmed() || model.isSelected()) {
getPainter().paintMenuItemBackground(b, g, checkIconRect, SwingConstants.HORIZONTAL, ThemePainter.STATE_PRESSED);
if (b.getIcon() == null) {
checkIcon.paintIcon(b, g, checkIconRect.x, checkIconRect.y);
}
}
else {
getPainter().paintMenuItemBackground(b, g, checkIconRect, SwingConstants.HORIZONTAL, ThemePainter.STATE_SELECTED);
if (b.getIcon() == null) {
checkIcon.paintIcon(b, g, checkIconRect.x, checkIconRect.y);
}
}
}
}
代码示例来源:origin: orbisgis/orbisgis
/**
* Set the selected menu item
* If isButtonAsMenuItem, apply the icon and tooltip of the menuitem to this button
* @param menu
*/
public void setSelectedItem(JMenuItem menu) {
selectedItem = menu;
if(buttonAsMenuItem) {
setIcon(menu.getIcon());
setText(menu.getText());
setToolTipText(menu.getToolTipText());
}
}
代码示例来源:origin: org.orbisgis/orbisgis-view
/**
* Set the selected menu item
* If isButtonAsMenuItem, apply the icon and tooltip of the menuitem to this button
* @param menu
*/
public void setSelectedItem(JMenuItem menu) {
selectedItem = menu;
if(buttonAsMenuItem) {
setIcon(menu.getIcon());
setText(menu.getText());
setToolTipText(menu.getToolTipText());
}
}
代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql
private JMenu cloneMenu(JMenu menu)
{
JMenu ret = new JMenu(menu.getText());
for (int i = 0; i < menu.getItemCount(); i++)
{
JMenuItem toClone = menu.getItem(i);
if (toClone instanceof JMenu)
{
ret.add(cloneMenu((JMenu) toClone));
}
else if(toClone instanceof JMenuItem)
{
JMenuItem clone = new JMenuItem(toClone.getText(), toClone.getIcon());
clone.setMnemonic(toClone.getMnemonic());
clone.setAction(toClone.getAction());
clone.setAccelerator(toClone.getAccelerator());
clone.setToolTipText(toClone.getToolTipText());
ret.add(clone);
}
else
{
ret.addSeparator();
}
}
return ret;
}
代码示例来源:origin: khuxtable/seaglass
static void paintIcon(Graphics g, SeaGlassMenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr) {
if (lh.getIcon() != null) {
Icon icon;
JMenuItem mi = lh.getMenuItem();
ButtonModel model = mi.getModel();
if (!model.isEnabled()) {
icon = mi.getDisabledIcon();
} else if (model.isPressed() && model.isArmed()) {
icon = mi.getPressedIcon();
if (icon == null) {
// Use default icon
icon = mi.getIcon();
}
} else {
icon = mi.getIcon();
}
if (icon != null) {
Rectangle iconRect = lr.getIconRect();
SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x,
iconRect.y, iconRect.width, iconRect.height);
}
}
}
代码示例来源:origin: org.fudaa.framework.fudaa/fudaa-common
/**
* Remplace un item menu en provenance de Bu par une action, plus gnraliste.
* @param _command La commande.
* @return L'action de remplacement, ou null si la commande n'existait pas.
*/
protected EbliActionAbstract replaceItemByAction(String _command) {
JMenuItem it=((JMenuItem)getMainMenuBar().getMenuItem(_command));
if (it==null) return null;
BuMenu mn=(BuMenu)getMainMenuBar().getMenuForAction(_command);
if (mn==null) return null;
int idx=mn.indexOf(_command);
if (idx==-1) return null;
EbliActionAbstract act=new EbliActionSimple(it.getText(),it.getIcon(),it.getActionCommand()) {
public void actionPerformed(ActionEvent _evt) {
FudaaCommonImplementation.this.actionPerformed(_evt);
}
};
act.setDefaultToolTip(it.getToolTipText());
act.setKey(it.getAccelerator());
mn.remove(idx);
mn.insert(act,idx)
// Pour rester compatible avec Bu.
.setName("mi"+_command);
return act;
}
内容来源于网络,如有侵权,请联系作者删除!