Example usage for javax.swing JFrame add

List of usage examples for javax.swing JFrame add

Introduction

In this page you can find the example usage for javax.swing JFrame 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) {

    JFrame frame = new JFrame();

    final JButton activate = new JButton("Show");
    frame.add(activate);

    frame.pack();/*from  ww  w . j a va  2 s.com*/
    frame.setVisible(true);

    final Main glass = new Main(frame);
    frame.setGlassPane(glass);

    activate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            glass.setVisible(true);
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JCheckBox a = new JCheckBox("A");
    a.setSelected(true);//from  w  w  w .  j a  v a  2 s  .co  m
    a.setMnemonic(KeyEvent.VK_A);

    JCheckBox b = new JCheckBox("B");
    JCheckBox c = new JCheckBox("C");
    JCheckBox d = new JCheckBox("D");

    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(new JLabel("Car Features"));
    frame.add(a);
    frame.add(b);
    frame.add(c);
    frame.add(d);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new GridLayout(N, N));
    for (int i = 0; i < N * N; i++) {
        frame.add(new CirclePanel());
    }//from w w  w  .j av a 2s .  co m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(300, 200);/*  w ww .j a  v  a2 s. c  om*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main());
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tp = new JTabbedPane();
    tp.addTab("Dates", new JPanel());
    tp.addTab("Deliveries", new JPanel());
    tp.addTab("Exports", new JPanel());

    tp.setTabComponentAt(0, new JLabel("Dates"));
    tp.setTabComponentAt(1, new JLabel("Deliveries"));
    tp.setTabComponentAt(2, new JLabel("Exports"));

    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(tp);
    frame.pack();//from  w  w  w.  j av a 2  s  . c o  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel topPanel = new JPanel();
    topPanel.setPreferredSize(new Dimension(200, 200));
    topPanel.setBackground(Color.WHITE);

    JTextArea chatArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(chatArea);

    JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
    mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    mainPanel.add(topPanel, BorderLayout.CENTER);
    mainPanel.add(scrollPane, BorderLayout.SOUTH);

    chatArea.getDocument().addDocumentListener(new DocumentListener() {

        @Override//from w  w w . j a  v  a  2s  .co  m
        public void insertUpdate(DocumentEvent e) {
            updateLineCount();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateLineCount();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateLineCount();
        }

        private void updateLineCount() {
            int lineCount = chatArea.getLineCount();
            if (lineCount <= 4) {
                chatArea.setRows(lineCount);
                mainPanel.revalidate();
            }
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(mainPanel);
    f.pack();
    f.setVisible(true);
}

From source file:BasicArrowButtonSample.java

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

    frame.setLayout(new GridLayout(0, 5));
    frame.add(new BasicArrowButton(BasicArrowButton.EAST));
    frame.add(new BasicArrowButton(BasicArrowButton.NORTH));
    frame.add(new BasicArrowButton(BasicArrowButton.SOUTH));
    frame.add(new BasicArrowButton(BasicArrowButton.WEST));
    frame.setSize(300, 200);/*from   w  ww  .j  a  va2s .c o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JRadioButton button1 = new JRadioButton("Red");
    JRadioButton button2 = new JRadioButton("Green");
    JRadioButton button3 = new JRadioButton("Blue");
    ButtonGroup colorButtonGroup = new ButtonGroup();
    colorButtonGroup.add(button1);/*from ww  w.  j a v a2 s  .  com*/
    colorButtonGroup.add(button2);
    colorButtonGroup.add(button3);
    button1.setSelected(true);

    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(new JLabel("Color:"));
    frame.add(button1);
    frame.add(button2);
    frame.add(button3);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JTextPane tp = new JTextPane();
    JButton withFocus = new JButton("Select with focus");
    withFocus.addActionListener(e -> {
        tp.selectAll();/*from w  w w. j a  va2s .c o  m*/
        tp.requestFocus();
    });
    JButton withOutFocus = new JButton("Select without focus");
    withFocus.addActionListener(e -> tp.selectAll());

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JScrollPane(tp));
    JPanel panel = new JPanel();
    panel.add(withFocus);
    panel.add(withOutFocus);
    frame.add(panel, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    DateFormatter[] formatters = new DateFormatter[] { new DateFormatter(new SimpleDateFormat("dd.MM.yyyy")),
            new DateFormatter(new SimpleDateFormat("ddMMyyyy")),
            new DateFormatter(new SimpleDateFormat("yyyy.MM.dd.")),
            new DateFormatter(new SimpleDateFormat("dd.MMM.yyyy")),
            new DateFormatter(new SimpleDateFormat("dd/MM/yyyy")) };
    MultiFormatter<DateFormatter> multiFormatter = new MultiFormatter<>(formatters);

    JFormattedTextField ftf = new JFormattedTextField(multiFormatter);
    ftf.setColumns(10);//from  w  ww  .j ava 2  s . c o  m

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(ftf);
    frame.add(new JButton("OK"));
    frame.pack();
    frame.setVisible(true);
}