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[] args) {
    JTabbedPane tab = new JTabbedPane();
    tab.addTab("New tab1", new JLabel("1"));
    tab.addTab("New Tab2", new JLabel("2"));
    JPanel p = new JPanel(new BorderLayout());
    p.add(new JLayer<JComponent>(tab, new TopRightCornerLabelLayerUI()));

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(p);//w w  w . j av  a  2s  . c  o m
    f.setSize(320, 240);
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JFormattedTextField Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box rowOne = Box.createHorizontalBox();
    rowOne.add(new JLabel("SSN:"));
    try {/*from www.  j  a v a 2s .co  m*/
        MaskFormatter mf1 = new MaskFormatter("###-##-####");
        rowOne.add(new JFormattedTextField(mf1));
    } catch (ParseException e) {
    }
    f.add(rowOne, BorderLayout.NORTH);

    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:LabelFor.java

public static void main(String args[]) {
    JFrame f = new JFrame("LabelFor Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    JLabel label = new JLabel("Username");
    JTextField textField = new JTextField();
    label.setDisplayedMnemonic(KeyEvent.VK_U);
    label.setLabelFor(textField);/*from   www . j  a  v a  2  s .co  m*/
    Container box = Box.createHorizontalBox();
    box.add(label);
    box.add(textField);
    content.add(box, BorderLayout.NORTH);
    content.add(new JButton("Submit"), BorderLayout.SOUTH);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    int nb = 4;//from   w  w w.j  a  va2s . c  o m
    final int frameCount = nb;

    for (int i = 0; i < frameCount; i++) {
        JFrame frame = new JFrame("Frame number " + i);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JPanel p = new JPanel(new BorderLayout());
        p.add(new JLabel("Click on the corner to close..."), BorderLayout.CENTER);
        frame.setContentPane(p);
        frame.setSize(200, 200);
        frame.setLocation(100 + 20 * i, 100 + 20 * i);
        frame.setVisible(true);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    BufferedImage origImg = ImageIO.read(url);

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(origImg)));

    File newFile = new File("new.png");
    ImageIO.write(origImg, "png", newFile);
    BufferedImage newImg = ImageIO.read(newFile);

    JOptionPane.showMessageDialog(null, new JLabel("New", new ImageIcon(newImg), SwingConstants.LEFT));
}

From source file:Main.java

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

    JLabel label = new JLabel("Label");
    label.setPreferredSize(new Dimension(1000, 1000));
    JScrollPane jScrollPane = new JScrollPane(label);

    JButton jButton1 = new JButton();

    jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jScrollPane.setViewportBorder(new LineBorder(Color.RED));
    jScrollPane.getViewport().add(jButton1, null);

    frame.add(jScrollPane, BorderLayout.CENTER);
    frame.setSize(400, 150);/*from  ww w.  j av a2s  . co  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(2, 2));
    BufferedImage bi = new BufferedImage(600, 200, BufferedImage.TYPE_INT_RGB);
    gui.add(new JLabel(new ImageIcon(bi)));

    JFrame myframe = new JFrame();
    JPanel myPanel = new JPanel();
    gui.add(myPanel, BorderLayout.PAGE_END);
    myPanel.setLayout(new GridLayout(2, 0, 0, 0));

    int x = 0;//from w  ww  . j  a  va2s  .  co m
    int y = 5;

    for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
        myPanel.add(new JButton(alphabet + ""));
        x++;
        if (x > 15) {
            y = 6;
            x = 0;
        }
    }
    myframe.add(gui);
    myframe.pack();
    myframe.setVisible(true);

    myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:BoxLayoutDemo.java

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

    JPanel panel = new JPanel();
    LayoutManager layout = new BoxLayout(panel, BoxLayout.X_AXIS);
    panel.setLayout(layout);/* w  w w .j  a v a2  s .c o m*/

    panel.add(new JLabel("a"));
    panel.add(new JLabel("b"));
    panel.add(new JLabel("c"));
    panel.add(new JLabel("d"));
    panel.add(new JLabel("e"));
    panel.add(new JLabel("f"));

    frame.add(panel);

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

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Label Focus Example");
    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);// ww  w. j  a v a  2  s.  c o  m
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.setSize(250, 150);
    frame.setVisible(true);

    textField.setText("Loooooooooooooooooooooooooooooooooooooooooooooooooooooooong");
    BoundedRangeModel model = textField.getHorizontalVisibility();
    int extent = model.getExtent();
    textField.setScrollOffset(extent);
    System.out.println("extent:" + extent);

}

From source file:ScrollSample.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "JScrollPane Sample" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Icon icon = new ImageIcon("dog.jpg");
    JLabel dogLabel = new JLabel(icon);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(dogLabel);
    //    scrollPane.getViewport().setView(dogLabel);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);/*from   w ww .  j  a  v a 2  s  .com*/
    frame.setVisible(true);
}