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

public static void main(String[] str) {
    JComboBox combo = new JComboBox();
    GregorianCalendar calendar = new GregorianCalendar();
    combo.addItem(calendar.getTime());/*  w  ww  . j a  v a 2s. c  om*/

    calendar.roll(GregorianCalendar.DAY_OF_MONTH, 1);
    combo.addItem(calendar.getTime());

    combo.setRenderer(new DateComboBoxRenderer());

    JFrame frame = new JFrame();

    JPanel panel = new JPanel();
    panel.add(new JLabel("Date Combo: "));
    panel.add(combo);

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

From source file:TimerBasedAnimation.java

public static void main(String[] args) {
    JFrame frame = new JFrame("TimerBasedAnimation");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new TimerBasedAnimation());
    frame.setSize(350, 250);//from   ww  w .j  ava2  s . c  o m
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            try {
                frame.add(new MyPanel());
            } catch (Exception e) {
                e.printStackTrace();/*  ww  w  .  j  av  a  2 s . c  o m*/
            }
            frame.setSize(250, 250);
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new LoginPanel());
    frame.pack();// w ww.j  a  v a  2 s  .c om
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TestPane center = new TestPane(100, 100);
    frame.add(center);
    frame.add(new TestPane(100, 50), BorderLayout.NORTH);
    frame.add(new TestPane(100, 50), BorderLayout.SOUTH);
    frame.add(new TestPane(50, 100), BorderLayout.EAST);
    frame.add(new TestPane(50, 100), BorderLayout.WEST);

    System.out.println("Size beofre pack = " + frame.getSize() + "; " + center.getSize());

    frame.pack();/* w  w w .  ja va2  s  .  co m*/

    System.out.println("Size after pack = " + frame.getSize() + "; " + center.getSize());

    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT));
    statusBar.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 4, 4, 4)));
    final JLabel status = new JLabel();
    statusBar.add(status);/*from   w  w  w  . j  a  va2  s  . co m*/

    JLabel content = new JLabel("Content in the middle");
    content.setHorizontalAlignment(JLabel.CENTER);

    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(content);
    frame.add(statusBar, BorderLayout.SOUTH);

    frame.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            status.setText(frame.getWidth() + "x" + frame.getHeight());
        }
    });

    frame.setBounds(20, 20, 200, 200);
    frame.setVisible(true);
}

From source file:JFramePack.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();
    frame.setTitle("My First Swing Application");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("Welcome");
    frame.add(label);
    frame.pack();//from   www.j  a v a 2 s .  c  om
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JLabel("Auto Hide"));
    frame.pack();// w  ww.  ja va2 s  .  com
    frame.setVisible(true);

    Timer autoHideTimer = new Timer(1000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
        }
    });
    autoHideTimer.setRepeats(false);

    frame.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseExited(MouseEvent e) {
            System.out.println("Restart...");
            autoHideTimer.restart();
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            System.out.println("Stop");
            autoHideTimer.stop();
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    String text = "one\ntwo\nthree\nfour\nfive";
    JFrame frame = new JFrame("title");
    JTextArea textArea = new JTextArea(text, 1, 30); // shows only one line
    JScrollPane scrollPane = new JScrollPane(textArea);
    frame.add(scrollPane);
    frame.pack();/* w  w  w. j  a  va 2 s .c o m*/
    frame.setVisible(true);

    final JViewport viewport = scrollPane.getViewport();

    textArea.addCaretListener(e -> {
        System.out.println("First : " + viewport.getViewPosition());
        System.out.println("Second: " + viewport.getViewPosition());
    });
    textArea.setCaretPosition(text.length());
}

From source file:ShowAction.java

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

    JButton bn = new JButton(new ShowAction(frame));

    frame.add(bn);

    frame.setSize(350, 250);/*from   w  w  w. j  a  va 2  s.  c  o  m*/
    frame.setVisible(true);
}