本文整理汇总了Java中javax.swing.JMenuItem.getIcon方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.getIcon方法的具体用法?Java JMenuItem.getIcon怎么用?Java JMenuItem.getIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.getIcon方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
void configureMenuItem(final JMenu parent, final JComponent c) {
if(c instanceof JMenuItem) {
JMenuItem item = (JMenuItem) c;
if(!(item.getIcon() instanceof WrapperIcon)) {
item.setIcon(new WrapperIcon(item.getIcon()));
}
installAcceleratorPreview(item);
item.setBorderPainted(true);
}
}
示例2: getTextFromIcon
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static String getTextFromIcon(JMenuItem mi) {
Icon icon = mi.getIcon();
if (icon != null && icon instanceof ImageIcon) {
String description = ((ImageIcon) icon).getDescription();
return getNameFromImageDescription(description);
}
return null;
}
示例3: drawSubselectedItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void drawSubselectedItem(Graphics2D g2, JMenuItem item) {
Point location = SwingUtilities.convertPoint(item, new java.awt.Point(0, 0), this);
g2.translate(location.x, location.y);
int iconGap = item.getIconTextGap();
int iconLeft = getIconLeft(item);
int iconWidth = getIconWidth(item);
int iconHeight = getIconHeight(item);
int iconTop = (item.getHeight() - iconHeight) / 2;
int accelWidth = getAcceleratorWidth(item);
int textWidth = item.getWidth() - iconLeft - iconWidth - iconGap - accelWidth;
int accelLeft = item.getWidth() - accelWidth;
// draw bounding boxes
g2.setColor(Color.LIGHT_GRAY);
//g2.drawRect(iconLeft, 0, iconWidth-1, item.getHeight()-1);
//g2.drawRect(textLeft, 0, textWidth-1, item.getHeight()-1);
//draw the accelerator areaa
//g2.drawRect(accelLeft, 0, accelWidth - 1, item.getHeight() - 1);
// draw the selection rectangles
g2.setStroke(SELECTION_STROKE);
g2.setColor(SELECTION_COLOR);
switch (canvas.getCurrentSelectedPortion()) {
case Icon:
{
if (item.getIcon() != null) {
g2.drawRect(iconLeft - 1, iconTop - 1, iconWidth + 1, iconHeight + 1);
}
break;
}
case Text:
{
g2.drawRect(iconLeft + iconWidth + iconGap - 1, -1, textWidth + 1, item.getHeight() + 1);
break;
}
case Accelerator:
{
if (item instanceof javax.swing.JMenu) {
break;
}
g2.drawRect(accelLeft - 1, -1, accelWidth + 1, item.getHeight() + 1);
break;
}
case All:
{
g2.drawRect(0, 0, item.getWidth() - 1, item.getHeight() - 1);
}
}
g2.translate(-location.x, -location.y);
}
示例4: getIconWidth
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static int getIconWidth(JMenuItem item) {
int iconWidth = item.getIcon() != null ? item.getIcon().getIconWidth() : 0;
return iconWidth;
}
示例5: getIconHeight
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static int getIconHeight(JMenuItem item) {
int iconHeight = item.getIcon() != null ? item.getIcon().getIconHeight() : 0;
return iconHeight;
}