本文整理汇总了Java中javax.swing.Icon.getIconWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Icon.getIconWidth方法的具体用法?Java Icon.getIconWidth怎么用?Java Icon.getIconWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.Icon
的用法示例。
在下文中一共展示了Icon.getIconWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintRotated
import javax.swing.Icon; //导入方法依赖的package包/类
public static void paintRotated(Graphics g, int x, int y, Direction dir, Icon icon, Component dest) {
if (!(g instanceof Graphics2D) || dir == Direction.EAST) {
icon.paintIcon(dest, g, x, y);
return;
}
Graphics2D g2 = (Graphics2D) g.create();
double cx = x + icon.getIconWidth() / 2.0;
double cy = y + icon.getIconHeight() / 2.0;
if (dir == Direction.WEST) {
g2.rotate(Math.PI, cx, cy);
} else if (dir == Direction.NORTH) {
g2.rotate(-Math.PI / 2.0, cx, cy);
} else if (dir == Direction.SOUTH) {
g2.rotate(Math.PI / 2.0, cx, cy);
} else {
g2.translate(-x, -y);
}
icon.paintIcon(dest, g2, x, y);
g2.dispose();
}
示例2: getIcon
import javax.swing.Icon; //导入方法依赖的package包/类
@Override
public Image getIcon(int type) {
Icon icon = data.getIcon();
if (icon instanceof ImageIcon) {
return ((ImageIcon) icon).getImage();
} else {
int w = icon.getIconWidth();
int h = icon.getIconHeight();
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(w, h);
Graphics2D g = image.createGraphics();
icon.paintIcon(null, g, 0, 0);
g.dispose();
return image;
}
}
示例3: icon2Image
import javax.swing.Icon; //导入方法依赖的package包/类
/**
* Converts given icon to a {@link java.awt.Image}.
*
* @param icon {@link javax.swing.Icon} to be converted.
*/
public static final Image icon2Image(Icon icon) {
if (icon == null) {
LOGGER.log(Level.WARNING, null, new NullPointerException());
return loadImage("org/openide/nodes/defaultNode.png", true);
}
if (icon instanceof ImageIcon) {
return ((ImageIcon) icon).getImage();
} else {
ToolTipImage image = new ToolTipImage("", icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
icon.paintIcon(new JLabel(), g, 0, 0);
g.dispose();
return image;
}
}
示例4: configureForNode
import javax.swing.Icon; //导入方法依赖的package包/类
private void configureForNode(Node node) {
renderer.reset();
Image nodeIcon = node.getIcon(BeanInfo.ICON_COLOR_16x16);
Icon icon = nodeIcon != null && nodeIcon != BreadcrumbsController.NO_ICON ? ImageUtilities.image2Icon(nodeIcon) : null;
int width = icon != null ? icon.getIconWidth() : 0;
if (width > 0) {
renderer.setIcon(icon);
renderer.setIconTextGap(ICON_TEXT_SEPARATOR);
} else {
renderer.setIcon(null);
renderer.setIconTextGap(0);
}
String html = node.getHtmlDisplayName();
if (html != null) {
renderer.setHtml(true);
renderer.setText(html);
} else {
renderer.setHtml(false);
renderer.setText(node.getDisplayName());
}
renderer.setFont(getFont());
}
示例5: paintIconForVertex
import javax.swing.Icon; //导入方法依赖的package包/类
public void paintIconForVertex(Graphics g, Vertex v, int x, int y) {
boolean outlineImages = false;
if(vertexIconFunction instanceof DemoVertexImageShapeFunction) {
outlineImages = ((DemoVertexImageShapeFunction)vertexIconFunction).isOutlineImages();
}
Icon icon = vertexIconFunction.getIcon(v);
if(icon == null || outlineImages) {
Shape s = AffineTransform.getTranslateInstance(x,y).
createTransformedShape(getVertexShapeFunction().getShape(v));
paintShapeForVertex((Graphics2D)g, v, s);
}
if(icon != null) {
int xLoc = x - icon.getIconWidth()/2;
int yLoc = y - icon.getIconHeight()/2;
icon.paintIcon(screenDevice, g, xLoc, yLoc);
}
}
示例6: getCloseButtonRectangle
import javax.swing.Icon; //导入方法依赖的package包/类
public void getCloseButtonRectangle(JComponent jc, Rectangle rect, Rectangle bounds) {
boolean rightClip = ((NimbusEditorTabCellRenderer) jc).isClipRight();
boolean leftClip = ((NimbusEditorTabCellRenderer) jc).isClipLeft();
boolean notSupported = !((NimbusEditorTabCellRenderer) jc).isShowCloseButton();
if (leftClip || rightClip || notSupported) {
rect.x = -100;
rect.y = -100;
rect.width = 0;
rect.height = 0;
} else {
String iconPath = findIconPath((NimbusEditorTabCellRenderer) jc);
Icon icon = TabControlButtonFactory.getIcon(iconPath);
int iconWidth = icon.getIconWidth();
int iconHeight = icon.getIconHeight();
rect.x = bounds.x + bounds.width - iconWidth - 2;
rect.y = bounds.y + (Math.max(0, bounds.height / 2 - iconHeight / 2));
rect.width = iconWidth;
rect.height = iconHeight;
}
}
示例7: getResizedIcon
import javax.swing.Icon; //导入方法依赖的package包/类
protected Icon getResizedIcon(Icon originalIcon) {
if(originalIcon == null) {
return null;
} else {
int width = originalIcon.getIconWidth();
int height = originalIcon.getIconHeight();
if(width != 48) {
double scale = 48.0D / (double)width;
BufferedImage bi = new BufferedImage((int)(scale * (double)width), (int)(scale * (double)height), 2);
Graphics2D g = bi.createGraphics();
g.setRenderingHints(HI_QUALITY_HINTS);
g.scale(scale, scale);
originalIcon.paintIcon((Component)null, g, 0, 0);
g.dispose();
return new ImageIcon(bi);
} else {
return originalIcon;
}
}
}
示例8: getIcon
import javax.swing.Icon; //导入方法依赖的package包/类
/**
* Returns the icon from this icon group with the specified name.
*
* @param name The name of the icon. For example, if you want the icon
* specified in <code>new.gif</code>, this value should be
* <code>new</code>.
* @return The icon, or <code>null</code> if it could not be found or
* loaded.
* @see #getLargeIcon
*/
public Icon getIcon(String name) {
Icon icon = getIconImpl(path + name + "." + extension);
// JDK 6.0 b74 returns icons with width/height==-1 in certain error
// cases (new ImageIcon(url) where url is not resolved?). We'll
// just return null in this case as Swing AbstractButtons throw
// exceptions when expected to paint an icon with width or height
// is less than 1.
if (icon!=null && (icon.getIconWidth()<1 || icon.getIconHeight()<1)) {
icon = null;
}
return icon;
}
示例9: createButton
import javax.swing.Icon; //导入方法依赖的package包/类
private static JButton createButton(String iconPath, String tooltip) {
Icon icon = ImageUtilities.loadImageIcon(iconPath, false);
final JButton button = new JButton(icon);
// ensure small size, just for the icon
Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
button.setPreferredSize(size);
button.setMargin(new Insets(1, 1, 1, 1));
button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
button.setToolTipText(tooltip);
button.setFocusable(false);
return button;
}
示例10: createButton
import javax.swing.Icon; //导入方法依赖的package包/类
private static JButton createButton (String iconPath, String tooltip) {
Icon icon = ImageUtilities.loadImageIcon(iconPath, false);
final JButton button = new JButton(icon);
// ensure small size, just for the icon
Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
button.setPreferredSize(size);
button.setMargin(new Insets(1, 1, 1, 1));
button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
button.setToolTipText(tooltip);
button.setFocusable(false);
return button;
}
示例11: paint
import javax.swing.Icon; //导入方法依赖的package包/类
/**
* paint is subclassed to draw the background correctly. JLabel
* currently does not allow backgrounds other than white, and it
* will also fill behind the icon. Something that isn't desirable.
*/
@Override
public void paint(Graphics g) {
Color bColor;
Icon currentI = getIcon();
if (selected) {
bColor = SELECTED_BACKGROUND_COLOR;
} else if (getParent() != null) /* Pick background color up from parent (which will come from
the JTree we're contained in). */ {
bColor = getParent().getBackground();
} else {
bColor = getBackground();
}
g.setColor(bColor);
if (currentI != null && getText() != null) {
int offset = (currentI.getIconWidth() + getIconTextGap());
if (getComponentOrientation().isLeftToRight()) {
g.fillRect(offset, 0, getWidth() - 1 - offset,
getHeight() - 1);
} else {
g.fillRect(0, 0, getWidth() - 1 - offset, getHeight() - 1);
}
} else {
g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
}
super.paint(g);
}
示例12: getButtonChildIndent
import javax.swing.Icon; //导入方法依赖的package包/类
/**
* Returns the amount to indent the specified component if it's
* a JCheckBox or JRadioButton. If the component is not a JCheckBox or
* JRadioButton, 0 will be returned.
*/
int getButtonChildIndent(JComponent c, int position) {
if ((c instanceof JRadioButton) || (c instanceof JCheckBox)) {
AbstractButton button = (AbstractButton)c;
Insets insets = c.getInsets();
Icon icon = getIcon(button);
int gap = button.getIconTextGap();
if (isLeftAligned(button, position)) {
return insets.left + icon.getIconWidth() + gap;
} else if (isRightAligned(button, position)) {
return insets.right + icon.getIconWidth() + gap;
}
}
return 0;
}
示例13: _setIcon
import javax.swing.Icon; //导入方法依赖的package包/类
private boolean _setIcon(int index, Icon i, final boolean[] widthChanged) {
if (i == null) {
i = TabData.NO_ICON;
}
TabData data = getTab(index);
if (i != data.getIcon()) {
widthChanged[0] = data.getIcon().getIconWidth()
!= i.getIconWidth();
data.icon = i;
return true;
} else {
return false;
}
}
示例14: getInPortOffset
import javax.swing.Icon; //导入方法依赖的package包/类
protected Point getInPortOffset(Icon icon, Dimension cellDimension) {
int iconHeight = icon.getIconHeight();
int iconWidth = icon.getIconWidth();
int xOff = (cellDimension.width - iconWidth) / 2 * 1000 / cellDimension.width;
int yOff = iconHeight / 2 * 1000 / cellDimension.height;
return new Point(xOff, yOff);
}
示例15: createDropDownButton
import javax.swing.Icon; //导入方法依赖的package包/类
private JButton createDropDownButton() {
Icon icon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/evaluator/drop_down_arrow.png", false);
final JButton button = new DropDownButton();
button.setIcon(icon);
String tooltipText = NbBundle.getMessage(CodeEvaluatorUI.class, "CTL_Expressions_Dropdown_tooltip");
button.setToolTipText(tooltipText);
button.setEnabled(false);
Dimension size = new Dimension(icon.getIconWidth() + 3, icon.getIconHeight() + 2);
button.setPreferredSize(size);
button.setMargin(new Insets(0, 0, 0, 0));
button.setFocusable(false);
AbstractAction action = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if ("pressed".equals(e.getActionCommand())) {
JComponent jc = (JComponent) e.getSource();
Point p = new Point(0, 0);
SwingUtilities.convertPointToScreen(p, jc);
if (!ButtonPopupSwitcher.isShown()) {
SwitcherTableItem[] items = createSwitcherItems();
ButtonPopupSwitcher.selectItem(jc, items, p.x, p.y);
}
//Other portion of issue 37487, looks funny if the
//button becomes pressed
if (jc instanceof AbstractButton) {
AbstractButton jb = (AbstractButton) jc;
jb.getModel().setPressed(false);
jb.getModel().setRollover(false);
jb.getModel().setArmed(false);
jb.repaint();
}
}
} // actionPerformed
@Override
public boolean isEnabled() {
return !getEditItemsList().isEmpty();
}
};
action.putValue(Action.SMALL_ICON, icon);
action.putValue(Action.SHORT_DESCRIPTION, tooltipText);
button.setAction(action);
return button;
}