本文整理汇总了Java中javax.swing.ImageIcon.getIconWidth方法的典型用法代码示例。如果您正苦于以下问题:Java ImageIcon.getIconWidth方法的具体用法?Java ImageIcon.getIconWidth怎么用?Java ImageIcon.getIconWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.ImageIcon
的用法示例。
在下文中一共展示了ImageIcon.getIconWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readIconFromFile
import javax.swing.ImageIcon; //导入方法依赖的package包/类
private Icon readIconFromFile( File iconFile ) {
try {
Image img = ImageIO.read( iconFile.toURL() );
if( null != img ) {
ImageIcon res = new ImageIcon( img );
if( res.getIconWidth() > 32 || res.getIconHeight() > 32 ) {
JOptionPane.showMessageDialog(this, NbBundle.getMessage(TextImporterUI.class, "Err_IconTooBig"), //NOI18N
NbBundle.getMessage(TextImporterUI.class, "Err_Title"), JOptionPane.ERROR_MESSAGE ); //NOI18N
return null;
}
return res;
}
} catch( ThreadDeath td ) {
throw td;
} catch( Throwable ioE ) {
//ignore
}
JOptionPane.showMessageDialog(this,
NbBundle.getMessage(TextImporterUI.class, "Err_CannotLoadIconFromFile", iconFile.getName()), //NOI18N
NbBundle.getMessage(TextImporterUI.class, "Err_Title"), JOptionPane.ERROR_MESSAGE ); //NOI18N
return null;
}
示例2: createActivateBreakpointsActionButton
import javax.swing.ImageIcon; //导入方法依赖的package包/类
@NbBundle.Messages({"CTL_DeactivateAllBreakpoints=Deactivate all breakpoints in current session",
"CTL_ActivateAllBreakpoints=Activate all breakpoints in current session",
"CTL_NoDeactivation=The current session does not allow to deactivate breakpoints",
"CTL_NoSession=No debugger session"})
public static AbstractButton createActivateBreakpointsActionButton() {
ImageIcon icon = ImageUtilities.loadImageIcon(DEACTIVATED_LINE_BREAKPOINT, false);
final JToggleButton button = new JToggleButton(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(Bundle.CTL_DeactivateAllBreakpoints());
button.setFocusable(false);
final BreakpointsActivator ba = new BreakpointsActivator(button);
button.addActionListener(ba);
DebuggerManager.getDebuggerManager().addDebuggerListener(DebuggerManager.PROP_CURRENT_ENGINE, new DebuggerManagerAdapter() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
DebuggerEngine de = (DebuggerEngine) evt.getNewValue();
ba.setCurrentEngine(de);
}
});
ba.setCurrentEngine(DebuggerManager.getDebuggerManager().getCurrentEngine());
return button;
}
示例3: serialize
import javax.swing.ImageIcon; //导入方法依赖的package包/类
@Override
public void serialize(ImageIcon vi, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
synchronized (vi) {
BufferedImage v = new BufferedImage(
vi.getIconWidth(),
vi.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics g = v.createGraphics();
// paint the Icon to the BufferedImage.
vi.paintIcon(null, g, 0, 0);
g.dispose();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(v, "png", baos);
byte [] data = baos.toByteArray();
jgen.writeStartObject();
jgen.writeStringField("type", "ImageIcon");
jgen.writeObjectField("imageData", data);
jgen.writeNumberField("width", v.getWidth());
jgen.writeNumberField("height", v.getHeight());
jgen.writeEndObject();
}
}
示例4: toBufferedImage
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* Converts a given Image into a BufferedImage
*
* @param img The Image to be converted
* @return The converted BufferedImage
*/
public static BufferedImage toBufferedImage(final ImageIcon img) {
final BufferedImage bimage = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
final Graphics2D bGr = bimage.createGraphics();
bGr.drawImage(img.getImage(), 0, 0, null);
bGr.dispose();
return bimage;
}
示例5: setPreview
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* resize and create the preview image
*
* @param path
*/
private void setPreview(String path) {
ImageIcon icon = new ImageIcon(path);
int w = icon.getIconWidth() > PREVIEW_SIZE.width ? PREVIEW_SIZE.width : icon.getIconWidth();
int h = icon.getIconHeight() > PREVIEW_SIZE.height ? PREVIEW_SIZE.height : icon.getIconHeight();
Image img = icon.getImage().getScaledInstance(w, h, Image.SCALE_SMOOTH);
previewObj.setIcon(new ImageIcon(img));
previewObj.setHorizontalAlignment(CENTER);
previewObj.setVerticalAlignment(CENTER);
previewObj.repaint();
}
示例6: loadImage
import javax.swing.ImageIcon; //导入方法依赖的package包/类
public void loadImage() {
if (file == null) {
return;
}
ImageIcon tmpIcon = new ImageIcon(file.getPath());
if (tmpIcon.getIconWidth() > 90) {
thumbnail = new ImageIcon(tmpIcon.getImage().
getScaledInstance(90, -1,
Image.SCALE_DEFAULT));
} else {
thumbnail = tmpIcon;
}
}
示例7: mirrorImage
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* Rotates image on y axis
* @param base image to be modified
* @return mirrored image
*/
protected ImageIcon mirrorImage(ImageIcon base) {
BufferedImage out = new BufferedImage(base.getIconWidth(), base.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = out.createGraphics();
g.drawImage(base.getImage(), base.getIconWidth(), 0, 0, base.getIconHeight(), 0, 0, base.getIconWidth(), base.getIconHeight(), null);
return new ImageIcon(out);
}
示例8: toBufferedImage
import javax.swing.ImageIcon; //导入方法依赖的package包/类
public static BufferedImage toBufferedImage(final ImageIcon icon) {
if (icon == null) return null;
final int w = icon.getIconWidth(), h = icon.getIconHeight();
final BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
final Graphics g = bi.createGraphics();
icon.paintIcon(null, g, 0,0);
g.dispose();
return bi;
}
示例9: rescale
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* Rescales an icon.
* @param src the original icon.
* @param newMinSize the minimum size of the new icon. The width and height of
* the returned icon will be at least the width and height
* respectively of newMinSize.
* @param an ImageObserver.
* @return the rescaled icon.
*/
public static ImageIcon rescale(ImageIcon src, Dimension newMinSize, ImageObserver observer) {
double widthRatio = newMinSize.getWidth() / (double) src.getIconWidth();
double heightRatio = newMinSize.getHeight() / (double) src.getIconHeight();
double scale = widthRatio > heightRatio ? widthRatio : heightRatio;
int w = (int) Math.round(scale * src.getIconWidth());
int h = (int) Math.round(scale * src.getIconHeight());
BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = dst.createGraphics();
g2.drawImage(src.getImage(), 0, 0, w, h, observer);
g2.dispose();
return new ImageIcon(dst);
}
示例10: dye
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* Fonte: https://stackoverflow.com/questions/21382966/colorize-a-picture-in-java
* MODIFICADO
* @param image
* @param color
* @return
*/
public static BufferedImage dye(ImageIcon image, Color color) {
int w = image.getIconWidth();
int h = image.getIconHeight();
BufferedImage dyed = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = dyed.createGraphics();
g.drawImage(image.getImage(), 0, 0, null);
g.setComposite(AlphaComposite.SrcAtop);
g.setColor(color);
g.fillRect(0, 0, w, h);
g.dispose();
return dyed;
}
示例11: Inicie
import javax.swing.ImageIcon; //导入方法依赖的package包/类
void Inicie(ParteAjuda sel) {
this.setTitle(sel.getTitulo());
if (sel.getByteImage() != null || sel.getHtml() != null) {//.isEmpty()) {
Pan.removeAll();
int H = 0;
int W = 0;
if (!sel.getHtml().isEmpty()) {
JLabel htmLbl = new JLabel();
htmLbl.setText(sel.getHtml());
htmLbl.repaint();
Dimension d = htmLbl.getPreferredSize();
int x = (getPreferredSize().width - d.width) / 2;
if (getPreferredSize().width < d.width) {
x = 0;
}
// int y = (getPreferredSize().height - d.height - subPan.getPreferredSize().height) / 2;
// if (getPreferredSize().height - subPan.getPreferredSize().height < d.height) {
// y = 0;
// }
htmLbl.setBounds(x, 0, d.width, d.height);
//Pan.setBackground(Color.yellow);
Pan.add(htmLbl);
H = d.height + 10;
W = d.width;
}
if (sel.getByteImage() != null) {
ImageIcon img = new ImageIcon(sel.getByteImage());
JLabel picLabel = new JLabel(img);
W = W > img.getIconWidth() ? W : img.getIconWidth();
picLabel.setBounds(0, H, img.getIconWidth(), img.getIconHeight());
picLabel.setPreferredSize(new Dimension(img.getIconWidth(), img.getIconHeight()));
H += img.getIconHeight();
Pan.setPreferredSize(new Dimension(W, H));
Pan.add(picLabel);
}
Pan.revalidate();
Pan.repaint();
}
}
示例12: setup
import javax.swing.ImageIcon; //导入方法依赖的package包/类
private void setup(ImageIcon image)
{
setBorder(null);
setOpaque(false);
image.setImageObserver(this);
this.setIcon(image);
height = image.getIconHeight();
width = image.getIconWidth();
}
示例13: renderHtml
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* Render a completion item using the provided icon and left and right
* html texts.
*
* @param icon icon 16x16 that will be displayed on the left. It may be null
* which means that no icon will be displayed but the space for the icon
* will still be reserved (to properly align with other items
* that will provide an icon).
*
* @param leftHtmlText html text that will be displayed on the left side
* of the item's rendering area next to the icon.
* <br/>
* It may be null which indicates that no left text will be displayed.
* <br/>
* If there's not enough horizontal space in the rendering area
* the text will be shrinked and "..." will be displayed at the end.
*
* @param rightHtmlText html text that will be aligned to the right edge
* of the item's rendering area.
* <br/>
* It may be null which means that no right text will be displayed.
* <br/>
* The right text is always attempted to be fully displayed unlike
* the left text that may be shrinked if there's not enough rendering space
* in the horizontal direction.
* <br/>
* If there's not enough space even for the right text it will be shrinked
* and "..." will be displayed at the end of the rendered string.
* @param g non-null graphics through which the rendering happens.
* @param defaultFont non-null default font to be used for rendering.
* @param defaultColor non-null default color to be used for rendering.
* @param width >=0 available width for rendering.
* @param height >=0 available height for rendering.
* @param selected whether the item being rendered is currently selected
* in the completion's JList. If selected the foreground color is forced
* to be black for all parts of the rendered strings.
*/
public static void renderHtml(ImageIcon icon, String leftHtmlText, String rightHtmlText,
Graphics g, Font defaultFont, Color defaultColor,
int width, int height, boolean selected) {
if (icon != null) {
// The image of the ImageIcon should already be loaded
// so no ImageObserver should be necessary
g.drawImage(icon.getImage(), BEFORE_ICON_GAP, (height - icon.getIconHeight()) /2, null);
}
int iconWidth = BEFORE_ICON_GAP + (icon != null ? icon.getIconWidth() : ICON_WIDTH) + AFTER_ICON_GAP;
int rightTextX = width - AFTER_RIGHT_TEXT_GAP;
FontMetrics fm = g.getFontMetrics(defaultFont);
int textY = (height - fm.getHeight())/2 + fm.getHeight() - fm.getDescent();
if (rightHtmlText != null && rightHtmlText.length() > 0) {
int rightTextWidth = (int)PatchedHtmlRenderer.renderHTML(rightHtmlText, g, 0, 0, Integer.MAX_VALUE, 0,
defaultFont, defaultColor, PatchedHtmlRenderer.STYLE_CLIP, false, true);
rightTextX = Math.max(iconWidth, rightTextX - rightTextWidth);
// Render right text
PatchedHtmlRenderer.renderHTML(rightHtmlText, g, rightTextX, textY, rightTextWidth, textY,
defaultFont, defaultColor, PatchedHtmlRenderer.STYLE_CLIP, true, selected);
rightTextX = Math.max(iconWidth, rightTextX - BEFORE_RIGHT_TEXT_GAP);
}
// Render left text
if (leftHtmlText != null && leftHtmlText.length() > 0 && rightTextX > iconWidth) { // any space for left text?
PatchedHtmlRenderer.renderHTML(leftHtmlText, g, iconWidth, textY, rightTextX - iconWidth, textY,
defaultFont, defaultColor, PatchedHtmlRenderer.STYLE_TRUNCATE, true, selected);
}
}
示例14: mergeIcons
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* Merge two icons together. Output icon dimension is the same as background one.
* @param background background icon
* @param overlay overlay icon, needs to be transparent (will be moved and cropped)
* @param cropMin minimum crop point for overlay icon (0,0 for no crop)
* @param cropMax maximum crop point for overlay icon (width and height for no crop)
* @param move upper left corner where cropped overlay image should be positioned on background image
* @return merged icon
*/
protected ImageIcon mergeIcons(ImageIcon background, ImageIcon overlay, Point cropMin, Point cropMax, Point move) {
BufferedImage out = new BufferedImage(background.getIconWidth(), background.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = out.createGraphics();
g.drawImage(background.getImage(), 0, 0, null);
g.drawImage(overlay.getImage(), move.x, move.y, move.x + cropMax.x - cropMin.x, move.y + cropMax.y - cropMin.y, cropMin.x, cropMin.y,
cropMax.x, cropMax.y, null);
return new ImageIcon(out);
}
示例15: JmtCell
import javax.swing.ImageIcon; //导入方法依赖的package包/类
/**
* Creates a graph cell and initializes it with the specified user object.
*
* @param userObject an Object provided by the user that constitutes
* the cell's data
*
* Conti Andrea 01-09-2003
* Bertoli Marco 04-giu-2005
*/
public JmtCell(String icon, Object userObject) {
super(userObject);
ImageIcon ico = JMTImageLoader.loadImage(icon);
GraphConstants.setIcon(attributes, ico);
imageDimension = new Dimension(ico.getIconWidth(), ico.getIconHeight());
GraphConstants.setSizeable(attributes, false);
GraphConstants.setSize(attributes, imageDimension);
}