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:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.PAGE_END);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);/*from www. j  ava2s . c o  m*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box rowOne = Box.createHorizontalBox();
    rowOne.add(new JLabel("Username"));
    rowOne.add(new JTextField());
    Box rowTwo = Box.createHorizontalBox();
    AccessibleContext context = rowTwo.getAccessibleContext();
    System.out.println(context);//from  ww w  .  j  a  v a  2  s.c  o  m

    rowTwo.add(new JLabel("Password"));
    rowTwo.add(new JPasswordField());
    f.add(rowOne, BorderLayout.NORTH);
    f.add(rowTwo, BorderLayout.SOUTH);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.LINE_END);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);/*  ww  w .  ja va2 s.c  om*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LINE_ENDS);

    frame.add(outerPanel);//  w w w.  j  a  va  2  s  .  c  o m
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);/*from  ww w.j  a  v a2  s.  c o  m*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Read from a URL
    URL url = new URL("http://java.org/source.gif");
    Image image = ImageIO.read(url);

    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();//from  www  .  j  a  v a 2s.co  m
    frame.setVisible(true);
}

From source file:Main.java

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

    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);

    JTextField textField = new JTextField();
    label.setLabelFor(textField);/*  w  w  w  .ja  v  a2s . c  o  m*/

    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            final Date date = new Date();
            final JLabel timeLabel = new JLabel(date.toString());
            Timer timer = new Timer(1000, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    date.setTime(System.currentTimeMillis());
                    timeLabel.setText(date.toString());
                }//from   w w  w. ja  va2s  .  c  om
            });
            timer.start();
            JOptionPane.showMessageDialog(null, timeLabel);
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JLabel userLabel = new JLabel("User Name");
    JLabel passLabel = new JLabel("Password");
    JTextField userText = new JTextField(20);
    JPasswordField passText = new JPasswordField(20);
    JButton loginButton = new JButton("Login");

    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridx = 0;/*from w ww  . j  a v  a 2  s. c o m*/
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(userLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(userText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(passLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(passText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridwidth = 2;
    panel.add(loginButton, gbc);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(panel));
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("your.ttf");
    FileInputStream in = new FileInputStream(f);
    Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
    Font dynamicFont32Pt = dynamicFont.deriveFont(32f);

    JLabel testLabel = new JLabel(dynamicFont.getName());
    testLabel.setFont(dynamicFont32Pt);//from  ww  w.j  a v a  2s.c o  m
    JFrame frame = new JFrame("Font Loading Demo");
    frame.getContentPane().add(testLabel);
    frame.pack();
    frame.setVisible(true);
}