本文整理汇总了Java中javax.swing.JLabel.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java JLabel.getWidth方法的具体用法?Java JLabel.getWidth怎么用?Java JLabel.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JLabel
的用法示例。
在下文中一共展示了JLabel.getWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAntialiasedColors
import javax.swing.JLabel; //导入方法依赖的package包/类
private static HashSet getAntialiasedColors(Object aaHint, int lcdContrast) {
JLabel label = new JLabel("ABCD");
label.setSize(label.getPreferredSize());
label.putClientProperty(KEY_TEXT_ANTIALIASING, aaHint);
label.putClientProperty(KEY_TEXT_LCD_CONTRAST, lcdContrast);
int w = label.getWidth();
int h = label.getHeight();
BufferedImage buffImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImage.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, w, h);
label.paint(g);
g.dispose();
HashSet<Color> colors = new HashSet<>();
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
Color color = new Color(buffImage.getRGB(i, j));
colors.add(color);
}
}
return colors;
}
示例2: scaleAndShowImage
import javax.swing.JLabel; //导入方法依赖的package包/类
/**
* Scales the given image to fit the label dimensions.
* @param bImage: The image to fit.
* @param label: The label to display the image.
*/
private void scaleAndShowImage(BufferedImage bImage, JLabel label) {
int bImageHeight = bImage.getHeight();
int bImageWidth = bImage.getWidth();
int labelHeight = label.getHeight();
int labelWidth = label.getWidth();
// Does this need to be scaled?
if (labelHeight >= bImageHeight && labelWidth >= bImageWidth) {
// If not, display the image and return.
ImageIcon image = new ImageIcon(bImage);
label.setIcon(image);
return;
}
// Calculate the new width and height for the image.
int newHeight;
int newWidth;
double bImageAspect = (double)bImageHeight / (double)bImageWidth;
double labelAspect = (double)labelHeight / (double)labelWidth;
if (bImageAspect > labelAspect) {
newHeight = labelHeight;
newWidth = (int)(((double)labelHeight / (double)bImageHeight) * (double)bImageWidth);
} else {
newWidth = labelWidth;
newHeight = (int)(((double)labelWidth / (double)bImageWidth) * (double)bImageHeight);
}
// Create a new image scaled to the correct size.
Image newImage = bImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
// Display the scaled image.
ImageIcon labelImage = new ImageIcon(newImage);
label.setIcon(labelImage);
label.validate();
label.repaint();
}
开发者ID:Azure-Samples,项目名称:cognitive-services-java-computer-vision-tutorial,代码行数:43,代码来源:MainFrame.java
示例3: aplicarTextura
import javax.swing.JLabel; //导入方法依赖的package包/类
/**
* Aplicar uma textura como plano de fundo no JLabel passado por parâmetro
* @param textura imagem da textura a ser aplicada
* @param label label que receberá a textura
*/
public static void aplicarTextura(ImageIcon textura, JLabel label) {
BufferedImage bi = Img.ImageIconToBufferedImage(textura);
BufferedImage bi2 = new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) bi2.getGraphics();
Rectangle r = new Rectangle(0, 0, bi.getWidth(), bi.getHeight());
g2.setPaint(new TexturePaint(bi, r));
Rectangle rect = new Rectangle(0, 0, label.getWidth(), label.getHeight());
g2.fill(rect);
g2.dispose();
label.setIcon(new ImageIcon(bi2));
}
示例4: executeWithUnitOutForAnimation
import javax.swing.JLabel; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void executeWithUnitOutForAnimation(JLabel unitLabel) {
final SwingGUI gui = (SwingGUI)getGUI();
final float scale = gui.getMapScale();
final int movementRatio = (int)(Math.pow(2, this.speed + 1) * scale);
final Rectangle r1 = gui.getTileBounds(this.sourceTile);
final Rectangle r2 = gui.getTileBounds(this.destinationTile);
final Rectangle bounds = r1.union(r2);
final double xratio = ImageLibrary.TILE_SIZE.width
/ (double)ImageLibrary.TILE_SIZE.height;
// Tile positions should be valid at this point.
final Point srcP = gui.getTilePosition(this.sourceTile);
if (srcP == null) {
logger.warning("Failed move animation for " + this.unit
+ " at source tile: " + this.sourceTile);
return;
}
final Point dstP = gui.getTilePosition(this.destinationTile);
if (dstP == null) {
logger.warning("Failed move animation for " + this.unit
+ " at destination tile: " + this.destinationTile);
return;
}
final int labelWidth = unitLabel.getWidth();
final int labelHeight = unitLabel.getHeight();
final Point srcPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
labelHeight, srcP);
final Point dstPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
labelHeight, dstP);
final int stepX = (srcPoint.getX() == dstPoint.getX()) ? 0
: (srcPoint.getX() > dstPoint.getX()) ? -1 : 1;
final int stepY = (srcPoint.getY() == dstPoint.getY()) ? 0
: (srcPoint.getY() > dstPoint.getY()) ? -1 : 1;
int dropFrames = 0;
Point point = srcPoint;
while (!point.equals(dstPoint)) {
long time = System.currentTimeMillis();
point.x += stepX * xratio * movementRatio;
point.y += stepY * movementRatio;
if ((stepX < 0 && point.x < dstPoint.x)
|| (stepX > 0 && point.x > dstPoint.x)) {
point.x = dstPoint.x;
}
if ((stepY < 0 && point.y < dstPoint.y)
|| (stepY > 0 && point.y > dstPoint.y)) {
point.y = dstPoint.y;
}
if (dropFrames <= 0) {
unitLabel.setLocation(point);
gui.paintImmediatelyCanvasIn(bounds);
int timeTaken = (int)(System.currentTimeMillis()-time);
final int waitTime = ANIMATION_DELAY - timeTaken;
if (waitTime > 0) {
Utils.delay(waitTime, "Animation interrupted.");
dropFrames = 0;
} else {
dropFrames = timeTaken / ANIMATION_DELAY - 1;
}
} else {
dropFrames--;
}
}
gui.refresh();
}