Example usage for javax.swing JLabel add

List of usage examples for javax.swing JLabel add

Introduction

In this page you can find the example usage for javax.swing JLabel add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ElliptIcon(380, 260, Color.red));
    label.setLayout(new GridLayout(2, 2));
    frame.setContentPane(label);/*from ww w .  ja  va  2  s  . com*/
    for (int i = 0; i < 4; i++) {
        label.add(new JLabel(new ElliptIcon(100, 60, Color.blue)));
    }
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame Main = new JFrame("Gradient Mask");
    JLabel imageLayer = new JLabel();
    JLabel maskLayer = new JLabel();
    BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    BufferedImage gradientMask = new GradientImage(image.getWidth(), image.getHeight(),
            new Color[] { new Color(255, 255, 255, 125), Color.BLACK }, GradientImage.RADIAL_FROM_CENTER)
                    .getImage();//from  w ww  . j  a va 2s . c  om
    Main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Main.setBounds(100, 50, image.getWidth(), image.getHeight());
    imageLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight());
    maskLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight());
    imageLayer.setIcon(new ImageIcon((Image) image));
    maskLayer.setIcon(new ImageIcon((Image) gradientMask));
    Main.getContentPane().add(imageLayer);
    imageLayer.add(maskLayer);
    Main.setVisible(true);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.OriginalMetadataComponent.java

/**
 * Reads the file and displays the result in a table.
 * //from  w ww . j  a v  a 2 s  . c o m
 * @param file The file to read.
 */
void setOriginalFile(File file) {
    metadataLoaded = true;
    if (file == null) {
        JLabel l = new JLabel("Metadata could not be retrieved.");
        l.setBackground(UIUtilities.BACKGROUND_COLOR);
        statusBar = UIUtilities.buildComponentPanel(l);
        statusBar.setBackground(UIUtilities.BACKGROUND_COLOR);
        removeAll();
        add(statusBar, BorderLayout.NORTH);
        return;
    }
    downloadButton.setEnabled(file.length() != 0);
    try {
        BufferedReader input = new BufferedReader(new FileReader(file));
        Map<String, List<String>> components = new LinkedHashMap<String, List<String>>();
        try {
            String line = null;
            List<String> l;
            String key = null;
            int start = 0;
            while ((line = input.readLine()) != null) {
                if (line.contains("=")) {
                    if (!StringUtils.isBlank(key)) {
                        l = components.get(key);
                        if (l != null)
                            l.add(line);
                    }
                } else {
                    line = line.trim();
                    if (line.length() > 0) {
                        start = getStart(line);
                        key = line.substring(start, line.length() - 1);
                        if (!StringUtils.isBlank(key))
                            components.put(key, new ArrayList<String>());
                    }
                }
            }
        } finally {
            input.close();
        }
        buildGUI(components);
        file.delete();
    } catch (IOException e) {
        file.delete();
        JLabel l = new JLabel("Loading metadata");
        l.setBackground(UIUtilities.BACKGROUND_COLOR);
        statusBar = UIUtilities.buildComponentPanel(l);
        statusBar.setBackground(UIUtilities.BACKGROUND_COLOR);
        removeAll();
        add(statusBar, BorderLayout.NORTH);
        Logger logger = MetadataViewerAgent.getRegistry().getLogger();
        LogMessage msg = new LogMessage();
        msg.print("An error occurred while reading metadata file.");
        msg.print(e);
        logger.error(this, msg);
    }
}