本文整理汇总了Java中javax.swing.JLabel.getIcon方法的典型用法代码示例。如果您正苦于以下问题:Java JLabel.getIcon方法的具体用法?Java JLabel.getIcon怎么用?Java JLabel.getIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JLabel
的用法示例。
在下文中一共展示了JLabel.getIcon方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeFitText
import javax.swing.JLabel; //导入方法依赖的package包/类
private static String computeFitText(JLabel label) {
String text = label.getText();
if(text == null) text = "";
if (text.length() <= VISIBLE_START_CHARS + 3) return text;
Icon icon = label.getIcon();
int iconWidth = icon != null ? icon.getIconWidth() : 0;
FontMetrics fm = label.getFontMetrics(label.getFont());
int width = label.getSize().width - iconWidth;
String sufix = "..."; // NOI18N
int sufixLength = fm.stringWidth(sufix);
int desired = width - sufixLength;
if (desired <= 0) return text;
for (int i = 0; i <= text.length() - 1; i++) {
String prefix = text.substring(0, i);
int swidth = fm.stringWidth(prefix);
if (swidth >= desired) {
return prefix.length() > 0 ? prefix + sufix: text;
}
}
return text;
}
示例2: isCellEditable
import javax.swing.JLabel; //导入方法依赖的package包/类
public boolean isCellEditable(final EventObject anEvent) {
if (anEvent instanceof MouseEvent) {
final MouseEvent event = (MouseEvent) anEvent;
final int row = treeTable.rowAtPoint(event.getPoint());
final Rectangle bounds = tree.getRowBounds(row);
int offset = bounds.x;
final Object node = tree.getPathForRow(row).getLastPathComponent();
final boolean leaf = tree.getModel().isLeaf(node);
final boolean expanded = tree.isExpanded(row);
final TreeCellRenderer tcr = tree.getCellRenderer();
final Component treeComponent = tcr.getTreeCellRendererComponent(
tree, node, true, expanded, leaf, row, false);
if (treeComponent instanceof JLabel) {
final JLabel label = (JLabel) treeComponent;
final Icon icon = label.getIcon();
if (icon != null) {
offset += icon.getIconWidth() + label.getIconTextGap();
}
}
if (event.getPoint().x < offset)
return false;
}
return deligate.isCellEditable(anEvent);
}
示例3: convertToBufferedImage
import javax.swing.JLabel; //导入方法依赖的package包/类
/**
* Converts the icon in labelMap in a buffered image.
*
* @param labelMap
* @return
*/
private static BufferedImage convertToBufferedImage(JLabel labelMap) {
ImageIcon imgIcon = ((ImageIcon) labelMap.getIcon());
Image image = imgIcon.getImage();
BufferedImage newImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = newImage.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return newImage;
}
示例4: executeWithUnitOutForAnimation
import javax.swing.JLabel; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void executeWithUnitOutForAnimation(JLabel unitLabel) {
final GUI gui = getGUI();
// Tile position should now be valid.
if (gui.getTilePosition(this.tile) == null) {
logger.warning("Failed attack animation for " + this.unit
+ " at tile: " + this.tile);
return;
}
final Rectangle rect = gui.getTileBounds(this.tile);
final ImageIcon icon = (ImageIcon)unitLabel.getIcon();
for (AnimationEvent event : animation) {
long time = System.nanoTime();
if (event instanceof ImageAnimationEvent) {
final ImageAnimationEvent ievent = (ImageAnimationEvent)event;
Image image = ievent.getImage();
if (mirror) {
// FIXME: Add mirroring functionality to SimpleZippedAnimation
image = ImageLibrary.createMirroredImage(image);
}
icon.setImage(image);
gui.paintImmediatelyCanvasIn(rect);
time = ievent.getDurationInMs()
- (System.nanoTime() - time) / 1000000;
if (time > 0) Utils.delay(time, "Animation delayed.");
}
}
gui.refresh();
}