Example usage for javax.swing JLabel JLabel

List of usage examples for javax.swing JLabel JLabel

Introduction

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

Prototype

public JLabel(Icon image) 

Source Link

Document

Creates a JLabel instance with the specified image.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    ResourceBundle rb = ResourceBundle.getBundle("MyResources", locale);
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("I18N Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(3, 2));
    frame.add(new JLabel(rb.getString("userName")));
    frame.add(new JTextField());
    frame.add(new JLabel(rb.getString("password")));
    frame.add(new JPasswordField());
    frame.add(new JButton(rb.getString("login")));
    frame.pack();/*from  w w w.jav a 2  s. com*/
    frame.setVisible(true);
}

From source file:GlassExample.java

/** Construct a Splash screen with the given image */
public static void main(String[] args) {
    JFrame f = new JFrame("GlassPane");

    final JPanel p1 = new JPanel();
    p1.add(new JLabel("GlassPane Example"));
    JButton show = new JButton("Show");
    p1.add(show);/*from  w w w.ja  v a  2s . c o m*/
    p1.add(new JButton("No-op"));
    f.getContentPane().add(p1);

    final JPanel glass = (JPanel) f.getGlassPane();

    glass.setVisible(true);
    glass.setLayout(new GridBagLayout());
    JButton glassButton = new JButton("Hide");
    glass.add(glassButton);

    f.setSize(150, 80);
    f.setVisible(true);

    boolean debug = false;
    if (debug) {
        System.out.println("Button is " + glassButton);
        System.out.println("GlassPane is " + glass);
    }

    // Add actions to the buttons...

    // show button (re-)shows the glass pane.
    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(true);
            p1.repaint();
        }
    });
    // hide button hides the Glass Pane to show what's under.
    glassButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(false);
            p1.repaint();
        }
    });
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Label Text Pos");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new GridLayout(2, 2));

    Border border = LineBorder.createGrayLineBorder();
    Icon warnIcon = MetalIconFactory.getTreeComputerIcon();

    JLabel label1 = new JLabel(warnIcon);
    label1.setText("Left-Bottom");
    label1.setHorizontalTextPosition(JLabel.LEFT);
    label1.setVerticalTextPosition(JLabel.BOTTOM);
    label1.setBorder(border);/* w w  w.jav a  2  s .  c om*/
    frame.add(label1);

    JLabel label2 = new JLabel(warnIcon);
    label2.setText("Right-TOP");
    label2.setHorizontalTextPosition(JLabel.RIGHT);
    label2.setVerticalTextPosition(JLabel.TOP);
    label2.setBorder(border);
    frame.add(label2);

    JLabel label3 = new JLabel(warnIcon);
    label3.setText("Center-Center");
    label3.setHorizontalTextPosition(JLabel.CENTER);
    label3.setVerticalTextPosition(JLabel.CENTER);
    label3.setBorder(border);
    frame.add(label3);

    JLabel label4 = new JLabel(warnIcon);
    label4.setText("Center-Bottom");
    label4.setHorizontalTextPosition(JLabel.CENTER);
    label4.setVerticalTextPosition(JLabel.BOTTOM);
    label4.setBorder(border);
    frame.add(label4);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextField account = new JTextField(10);
    JPanel accountPanel = new JPanel(new GridLayout());
    accountPanel.add(account);/*from w  w  w.  j av  a 2s  .  co  m*/
    accountPanel.setBorder(new TitledBorder("Account"));

    String[] firstDigitList = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

    JLabel firstDigitListLabel = new JLabel("Leading Digit Change");
    JPanel firstDigitListPanel = new JPanel(new BorderLayout(4, 2));
    firstDigitListPanel.add(firstDigitListLabel, BorderLayout.WEST);
    JComboBox firstDigitCombo = new JComboBox(firstDigitList);
    firstDigitListPanel.add(firstDigitCombo);
    firstDigitCombo.setSelectedIndex(0);
    firstDigitListPanel.setBorder(new TitledBorder("LDC"));

    JPanel panel = new JPanel();
    panel.add(accountPanel);
    panel.add(firstDigitListPanel);

    int result = JOptionPane.showConfirmDialog(null, panel, "Please Enter Values",
            JOptionPane.OK_CANCEL_OPTION);
}

From source file:Main.java

public static void main(String[] args) {
    final StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<body><ol>");
    Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (Font font : fonts) {
        String name = font.getName();
        sb.append("<li style='font-family: " + name + "; font-size: 20px;'>");
        sb.append(name);/* w  w w.  j a v  a  2  s .  c  o m*/
    }

    JScrollPane sp = new JScrollPane(new JLabel(sb.toString()));
    Dimension d = sp.getPreferredSize();
    sp.setPreferredSize(new Dimension(d.width, 150));
    JOptionPane.showMessageDialog(null, sp);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(5, 5));

    int sz = 4;//from ww  w .  j  a  v a  2  s  .  c o  m
    Container content = new JPanel(new GridLayout(sz, 0, 2, 2));
    for (int f = 0; f < sz * sz; f++) {
        content.add(new JButton());
    }
    gui.add(content, BorderLayout.CENTER);

    Container info = new JPanel(new FlowLayout(FlowLayout.CENTER, 50, 5));
    info.add(new JLabel("Flow"));
    info.add(new JLabel("Layout"));
    gui.add(info, BorderLayout.PAGE_START);

    gui.add(new JLabel("Label"), BorderLayout.LINE_END);

    JOptionPane.showMessageDialog(null, gui);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    JFrame frame = new JFrame("Number Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = new Font("SansSerif", Font.BOLD, 16);

    JLabel label;//from  www. j  a v a 2 s  . c om
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    label = new JLabel("Raw Number:");
    input = new JFormattedTextField(2424.50);
    input.setValue(2424.50);
    input.setColumns(20);
    input.setFont(font);
    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);
    frame.add(panel);

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

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH);

    String days[] = symbols.getWeekdays();
    SpinnerModel model1 = new SpinnerListModel(days);
    JSpinner spinner1 = new JSpinner(model1);

    JLabel label1 = new JLabel("French Days/List");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.NORTH);

    frame.setSize(200, 90);/*from  www  .j a v  a  2 s  . c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    JPanel northPanel = new JPanel(new GridLayout(2, 1));

    JPanel welcomePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    welcomePanel.add(new JLabel("Welcome"));

    northPanel.add(welcomePanel);/*from   ww  w .j a v  a 2 s  .c om*/

    JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    JRadioButton button1 = new JRadioButton("Button 1", true);
    JRadioButton button2 = new JRadioButton("Button 2", false);

    ButtonGroup group = new ButtonGroup();
    group.add(button1);
    group.add(button2);

    radioPanel.add(button1);
    radioPanel.add(button2);

    northPanel.add(radioPanel);

    JPanel middlePanel = new JPanel(new GridLayout(3, 3));

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            middlePanel.add(new JButton("Button " + i + j));
        }
    }

    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    southPanel.add(new JLabel("Whose turn:"));
    southPanel.add(new JButton("Reset"));

    frame.add(northPanel, BorderLayout.NORTH);
    frame.add(middlePanel, BorderLayout.CENTER);
    frame.add(southPanel, BorderLayout.SOUTH);

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

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Number Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = new Font("SansSerif", Font.BOLD, 16);

    JLabel label;//from  ww w. j  a v a2  s . com
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    label = new JLabel("Raw Number:");
    input = new JFormattedTextField(2424.50);
    input.setValue(2424.50);
    input.setColumns(20);
    input.setFont(font);

    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);
    frame.add(panel);

    frame.add(new JTextField());
    frame.pack();
    frame.setVisible(true);
}