Example usage for javax.swing JPanel add

List of usage examples for javax.swing JPanel add

Introduction

In this page you can find the example usage for javax.swing JPanel 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) {
    String[] items = { "1|9|2", "1|9|1", "1|4|7" };
    JList list = new JList(items);
    JPanel panel = new JPanel();
    panel.add(new JScrollPane(list));
    JOptionPane.showMessageDialog(null, panel);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JLabel label = new JLabel("java2s.com");

    JPanel panel = new JPanel();
    panel.add(label);
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    JOptionPane.showMessageDialog(null, panel);

}

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel pnl = new JPanel();
    pnl.add(new MyButton());
    frame.add(pnl);/*from ww  w  .  j a  va2  s  .c o  m*/
    frame.setSize(600, 600);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JComponent button = new JButton("Cut");
    String tooltiptext = "<html>" + "This is the " + "<img src=\"file:cut.gif\">" + " tool tip text."
            + "</html>";
    button.setToolTipText(tooltiptext);/*from w  w w  .ja  va  2s.  c  o m*/
    JPanel panel = new JPanel();
    panel.add(button);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    Object[] options1 = { "Try This Number", "Choose A Random Number", "Quit" };

    JPanel panel = new JPanel();
    panel.add(new JLabel("Enter number between 0 and 1000"));
    JTextField textField = new JTextField(10);
    panel.add(textField);/* w  w  w .ja  v a2  s  . c  o m*/

    int result = JOptionPane.showOptionDialog(null, panel, "Enter a Number", JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE, null, options1, null);
    if (result == JOptionPane.YES_OPTION) {
        JOptionPane.showMessageDialog(null, textField.getText());
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    JPanel centeredPanel = new JPanel();
    centeredPanel.add(new JButton("one"));
    centeredPanel.add(new JButton("two"));

    f.getContentPane().add(centeredPanel);
    f.pack();/*from  www . j  ava 2 s . c  om*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    DefaultListModel<String> dlm = new DefaultListModel();
    String[] modelElems = { "Apple", "Orange", "Banana" };
    for (int i = 0; i < modelElems.length; i++)
        dlm.add(i, modelElems[i]);/*from w w w. j  a  v a  2 s .  c o  m*/

    JList<String> lstFruitList = new JList(dlm);
    lstFruitList.setVisible(true);

    JPanel p = new JPanel();
    p.add(lstFruitList);
    f.add(p);
    f.setLocation(0, 0);
    f.setSize(400, 400);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    MyTextField component = new MyTextField(10);
    MyTextField component2 = new MyTextField(10);

    JPanel p = new JPanel();
    p.add(component);
    p.add(component2);/*from  w w  w.  j a va 2s . c om*/
    JOptionPane.showMessageDialog(null, p);

}

From source file:Main.java

public static void main(String[] args) {
    String[] items = { "item1", "item2", "item1" };
    JList<String> list = new JList<>(items);
    JTextField output = new JTextField(15);
    JPanel gui = new JPanel();
    gui.add(list);
    gui.add(output);/*  w w w.  ja  v a  2 s  . co m*/
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent lse) {
            int index = list.getSelectedIndex();
            String outputText = "Index: " + index + "  Value: " + items[index];
            output.setText(outputText);
        }
    });
    JOptionPane.showMessageDialog(null, gui);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setUndecorated(true);//from   w w w. j  av  a 2s. c o  m
    JPanel panel = new JPanel();
    panel.add(new JLabel("Stackoverflow!"));
    panel.add(new JButton(new AbstractAction("Close") {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    }));
    f.add(panel);
    f.pack();
    f.setVisible(true);
}