本文整理匯總了Java中javax.swing.JLabel.repaint方法的典型用法代碼示例。如果您正苦於以下問題:Java JLabel.repaint方法的具體用法?Java JLabel.repaint怎麽用?Java JLabel.repaint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JLabel
的用法示例。
在下文中一共展示了JLabel.repaint方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Inicie
import javax.swing.JLabel; //導入方法依賴的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();
}
}
示例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