本文整理匯總了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;
}