当前位置: 首页>>代码示例>>Java>>正文


Java JLabel.repaint方法代码示例

本文整理汇总了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();
        }
    }
 
开发者ID:chcandido,项目名称:brModelo,代码行数:40,代码来源:FrameSobre.java

示例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


注:本文中的javax.swing.JLabel.repaint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。