Example usage for javax.swing JLabel setPreferredSize

List of usage examples for javax.swing JLabel setPreferredSize

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel p = new JPanel(new BorderLayout());
    JTextField tf = new JTextField(5);
    JLabel label = new JLabel(new ImageIcon("Test.gif"));
    label.setOpaque(true);// w  w w. j  av a2  s . co m
    label.setBackground(tf.getBackground());
    label.setPreferredSize(new Dimension(label.getPreferredSize().width, tf.getPreferredSize().height));
    p.setBorder(tf.getBorder());
    tf.setBorder(null);
    p.add(label, BorderLayout.WEST);
    p.add(tf, BorderLayout.CENTER);
    JPanel p1 = new JPanel();
    p1.add(p);
    getContentPane().add(p1);
    pack();
    setLocationRelativeTo(null);
}

From source file:de.iew.imageupload.widgets.ContentPane.java

public void registerImageFile(File file) {
    try {//ww  w . j  a  v  a2s  .co m
        ImageIcon imageIcon = new ImageIcon(file.getAbsolutePath());
        JLabel imageLabel = new JLabel(imageIcon, JLabel.CENTER);
        imageLabel.setPreferredSize(new Dimension(100, 100));
        imageLabel.setSize(new Dimension(100, 100));
        imageLabel.addMouseListener(this.imageMouseClickHandler);
        imageLabel.setBackground(Color.WHITE);
        imageLabel.setBorder(new EmptyBorder(10, 10, 10, 10));
        imageLabel.putClientProperty("Image File", file);

        this.imageGridPane.add(imageLabel);
        this.imageGridPane.revalidate();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected,
            cellHasFocus);/*w w  w. ja v  a  2s .com*/
    if (value instanceof Color) {
        renderer.setBackground((Color) value);
    }
    renderer.setPreferredSize(preferredSize);
    return renderer;
}

From source file:com.game.ui.views.MapEditor.java

public void generateGUI() throws IOException {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    //        setResizable(false);
    JMenuBar menubar = new JMenuBar();
    ImageIcon icon = null;/*from   ww  w . j av  a2 s. c  o m*/
    try {
        icon = GameUtils.shrinkImage("save.png", 20, 20);
    } catch (IOException e) {
        System.out.println("Dialog : showDialogForMap(): Exception occured :" + e);
        e.printStackTrace();
    }
    JMenu file = new JMenu("File");
    JMenuItem save = new JMenuItem("Save", icon);
    save.setToolTipText("Save Map Information");
    save.setActionCommand("Save Map");
    save.addActionListener(this);
    file.add(save);
    menubar.add(file);
    setJMenuBar(menubar);
    JPanel topPanel = new JPanel();
    topPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    topPanel.setLayout(new GridBagLayout());
    JLabel headerLbl = new JLabel("Legend : ");
    headerLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    JLabel lbl1 = new JLabel();
    lbl1.setPreferredSize(new Dimension(50, 20));
    lbl1.setBackground(Configuration.pathColor);
    lbl1.setOpaque(true);
    JLabel lbl2 = new JLabel("- Represents the path.");
    JLabel lbl3 = new JLabel();
    lbl3.setPreferredSize(new Dimension(50, 20));
    lbl3.setBackground(Configuration.enemyColor);
    lbl3.setOpaque(true);
    JLabel lbl4 = new JLabel("- Represents the path with monsters");
    JLabel lbl5 = new JLabel();
    lbl5.setPreferredSize(new Dimension(50, 20));
    lbl5.setBackground(Configuration.startPointColor);
    lbl5.setOpaque(true);
    JLabel lbl6 = new JLabel("- Represents the starting point in the path");
    JLabel lbl7 = new JLabel();
    lbl7.setBackground(Configuration.endPointColor);
    lbl7.setOpaque(true);
    lbl7.setPreferredSize(new Dimension(50, 20));
    JLabel lbl8 = new JLabel("- Ending point in the path");
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.insets = new Insets(5, 5, 5, 5);
    c.gridwidth = 2;
    topPanel.add(headerLbl, c);
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.ipadx = 5;
    c.ipady = 5;
    topPanel.add(lbl1, c);
    c.gridx = 1;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    topPanel.add(lbl2, c);
    c.gridx = 0;
    c.gridy = 2;
    topPanel.add(lbl3, c);
    c.gridx = 1;
    topPanel.add(lbl4, c);
    c.gridx = 0;
    c.gridy = 3;
    topPanel.add(lbl5, c);
    c.gridx = 1;
    topPanel.add(lbl6, c);
    c.gridx = 0;
    c.gridy = 4;
    topPanel.add(lbl7, c);
    c.gridx = 1;
    topPanel.add(lbl8, c);
    add(topPanel, BorderLayout.NORTH);
    bottomPanel = new JPanel();
    add(bottomPanel, BorderLayout.CENTER);
    bottomPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    //        bottomPanel.add(new JButton("kaushik"));
    pack();
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    setMaximizedBounds(env.getMaximumWindowBounds());
    setVisible(true);
    callDialogForUsersInput();
}

From source file:AlignLabels.java

JLabel createLabel(String text) {
    String separator = System.getProperty("line.separator");
    JLabel label = new JLabel(text + separator + "multiline" + separator + "label");
    label.setToolTipText(text + "\n\ndoubled space\n\ntooltip");
    label.setBorder(BorderFactory.createEtchedBorder());
    this.add(label);
    label.setPreferredSize(new Dimension(125, 125));
    return label;
}

From source file:utilities.GraphViewer.java

public void addSensor(String fichier) {

    // ajouter le graphe

    ajouterFichier(fichier);/*from www  .  jav a2 s  .co m*/
    // this.paneGraphe.add(graphe());
    graphe.revalidate();

    db.add(this.getSensorName(fichier), fichier);

    // ajouter un element a la list
    JCheckBox chckbxNewCheckBox = new JCheckBox(this.getSensorName(fichier));
    this.sensors.add(chckbxNewCheckBox);
    this.sensors1.add(chckbxNewCheckBox);
    chckbxNewCheckBox.setBackground(new Color(200, 200, 255));
    chckbxNewCheckBox.setBorder(new LineBorder(Color.BLACK));
    chckbxNewCheckBox.setSelected(true);
    chckbxNewCheckBox.addActionListener(this);
    JLabel l = new JLabel(" ");
    l.setPreferredSize(new Dimension(50, 5));
    this.sensorsList.add(l);
    this.sensorsList.add(chckbxNewCheckBox);
    this.sensorsList.validate();

}

From source file:Interface.ResultadoJanela.java

public ResultadoJanela(List<Resultado> tar, List<Resultado> jac, List<Resultado> och, List<Resultado> sbi) {
    //  super("Resultado");
    CategoryDataset dataset;//from  www  .  j a  va2s . c  o  m

    //---------------------gerando resultados tarantula-------------------------------------
    dataset = gerarDataset(tar, jac, och, sbi);
    JFreeChart chart = gerarGrafico(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);

    JLabel lAjuda = new JLabel("Ajuda", JLabel.RIGHT);
    lAjuda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icone_informacao.gif"))); // NOI18N
    lAjuda.setPreferredSize(new Dimension(50, 50));
    lAjuda.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            lAjudaMouseClicked(evt);
        }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(lAjuda, BorderLayout.BEFORE_FIRST_LINE);
    panel.add(chartPanel, BorderLayout.LINE_START);
    JLabel lTabela = new JLabel("Tabela de Resultados", JLabel.CENTER);
    panel.add(lTabela, BorderLayout.SOUTH);

    JTable table = new JTable(criarValores(tar, jac, och, sbi), criarColunas());

    // Adiciona o JTable dentro do painel
    JScrollPane scrollPane = new JScrollPane(table);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    panel.add(scrollPane, BorderLayout.SOUTH);

    JFrame frame = new JFrame();
    frame.setTitle("JLoc - Resultado");
    frame.setVisible(true);
    frame.add(panel);

    frame.pack();
    frame.setVisible(true);
}

From source file:components.LayeredPaneDemo2.java

private JLabel createColoredLabel(String text, Color color) {
    JLabel label = new JLabel(text);
    label.setVerticalAlignment(JLabel.TOP);
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setOpaque(true);/*from   w  ww.j a  va  2 s .  c  om*/
    label.setBackground(color);
    label.setForeground(Color.black);
    label.setBorder(BorderFactory.createLineBorder(Color.black));
    label.setPreferredSize(new Dimension(140, 140));
    return label;
}

From source file:de.codesourcery.flocking.ui.NumberInputField.java

/**
 * Create instance./*from  w ww  .j ava 2  s . com*/
 *  
 * <p>Creates a resizable panel that holds a label, a textfield and a slider
 * for entering/adjusting a numeric value.</p>
 * 
 * @param label the label to display
 * @param model the model that is used to read/write the value to be edited. If the model returns <code>null</code> values,
 * these will be treated as "0" (or "0.0" respectively).
 * @param minValue valid minimum value (inclusive) the user may enter
 * @param maxValue vali maximum value (inclusive) the user may enter
 * @param onlyIntValues whether the user may enter only integers or integers <b>and</b> floating-point numbers. 
 */
public NumberInputField(String label, IModel<T> model, double minValue, double maxValue,
        final boolean onlyIntValues) {
    if (model == null) {
        throw new IllegalArgumentException("model must not be NULL.");
    }

    this.model = model;
    this.minValue = minValue;
    this.maxValue = maxValue;
    this.onlyIntValues = onlyIntValues;

    textField = new JTextField("0");
    textField.setColumns(5);
    textField.setHorizontalAlignment(JTextField.RIGHT);

    slider = new JSlider(0, SLIDER_RESOLUTION);

    textField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (selfTriggeredEvent) {
                return;
            }

            final String s = textField.getText();
            if (!StringUtils.isBlank(s)) {
                Number number = null;
                try {
                    if (onlyIntValues) {
                        number = Long.parseLong(s.trim());
                    } else {
                        number = Double.parseDouble(s.trim());
                    }
                } catch (Exception ex) {
                    textField.setText(numberToString(NumberInputField.this.model.getObject()));
                    return;
                }

                updateModelValue(number);
            }
        }
    });

    textField.setText(numberToString(model.getObject()));

    slider.getModel().setValue(calcSliderValue(model.getObject()));
    slider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (selfTriggeredEvent) {
                return;
            }
            final double percentage = slider.getModel().getValue() / (double) SLIDER_RESOLUTION; // 0...1

            final double range = Math.abs(NumberInputField.this.maxValue - NumberInputField.this.minValue);
            final double newValue = NumberInputField.this.minValue + range * percentage;

            updateModelValue(newValue);
        }
    });

    slider.setMinimumSize(new Dimension(100, 20));
    slider.setPreferredSize(new Dimension(100, 20));

    // do layout
    setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = new GridBagConstraints();
    cnstrs.fill = GridBagConstraints.NONE;
    cnstrs.weightx = 0;
    cnstrs.weighty = 0;
    cnstrs.gridx = 0;
    cnstrs.gridy = 0;

    final JLabel l = new JLabel(label);
    l.setMinimumSize(new Dimension(1500, 20));
    l.setPreferredSize(new Dimension(150, 20));
    l.setVerticalAlignment(SwingConstants.TOP);
    add(l, cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.fill = GridBagConstraints.NONE;
    cnstrs.weightx = 0;
    cnstrs.weighty = 0;
    cnstrs.gridx = 1;
    cnstrs.gridy = 0;
    cnstrs.insets = new Insets(0, 0, 0, 10);

    add(textField, cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.fill = GridBagConstraints.HORIZONTAL;
    cnstrs.weightx = 1.0;
    cnstrs.weighty = 1.0;
    cnstrs.gridx = 2;
    cnstrs.gridy = 0;

    add(slider, cnstrs);
}

From source file:org.onesun.sdi.swing.app.views.DataServicesView.java

private void addControlsToPanel() {
    dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    dataTable.setAutoscrolls(true);/*from  w  w w .j ava 2s . co  m*/

    JPanel panel = null;

    panel = new JPanel(new SpringLayout());
    panel.add(copyDataButton);
    SpringLayoutUtils.makeCompactGrid(panel, 1, 1, 5, 5, 5, 5);
    this.add(panel);

    panel = new JPanel(new SpringLayout());
    panel.add(containerPanel);
    SpringLayoutUtils.makeCompactGrid(panel, 1, 1, 5, 5, 5, 5);
    this.add(panel);

    panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    panel.add(executeButton);
    panel.add(computeMetricsButton);
    this.add(panel);

    panel = new JPanel(new SpringLayout());
    JLabel label = new JLabel("Enriched Data", JLabel.LEADING);
    label.setPreferredSize(new Dimension(150, 24));
    scrollPane.setPreferredSize(new Dimension(250, 900));

    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

    panel.add(label);
    label.setLabelFor(scrollPane);
    panel.add(scrollPane);
    SpringLayoutUtils.makeCompactGrid(panel, 2, 1, 5, 5, 5, 5);
    this.add(panel);

    panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel.add(rowCountLabel);
    this.add(panel);
}