Example usage for javax.swing JFrame JFrame

List of usage examples for javax.swing JFrame JFrame

Introduction

In this page you can find the example usage for javax.swing JFrame JFrame.

Prototype

public JFrame() throws HeadlessException 

Source Link

Document

Constructs a new frame that is initially invisible.

Usage

From source file:Main.java

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

    JTextField jTextField1 = new JTextField();

    jTextField1.setText("jTextField1");
    jTextField1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("action");
        }//from   w  w w. j a v  a2 s  .  co m
    });
    frame.add(jTextField1);

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

From source file:CreateDialogFromOptionPane.java

public static void main(final String[] args) {
    JFrame parent = new JFrame();
    JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    JDialog dialog = optionPane.createDialog(parent, "Manual Creation");
    dialog.setVisible(true);//ww w .j av a  2  s .  com
}

From source file:HTMLDemoAbstractButton.java

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

    AbstractButton bn = new JButton();
    bn.setText("<html>Last Name<br><font face='courier new'" + " color=red> (mandatory) </font></html>");
    frame.add(bn);/*from  w  w  w  .j  a  v a 2  s . c  o m*/

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

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JScrollBar oneJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    frame.add(oneJScrollBar, BorderLayout.NORTH);
    frame.setSize(200, 44);//from   w  ww.ja  v  a  2s  . co  m
    frame.setVisible(true);

}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JRootPane root = f.getRootPane();
    Container content = root.getContentPane();
    content.add(new JButton("Hello"));
    f.pack();//from w  ww.  j  av a  2  s .c o m
    f.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);//from ww w . j ava 2  s.c o m
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    final JFrame frame = new JFrame();
    frame.setUndecorated(true);/*from   w w w  .  j  av  a  2  s .  co m*/
    JButton button = new JButton("Minimize");
    button.addActionListener(e -> frame.setState(Frame.ICONIFIED));
    frame.add(button);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}

From source file:HtmlToolTipDemo.java

public static void main(String[] a) {
    JFrame mainFrame = new JFrame();

    JLabel label = new JLabel("label");

    label.setToolTipText("<html>First line<br>Second Line</html>");
    mainFrame.getContentPane().add(label);

    mainFrame.setSize(100, 100);/*from   www . j  av  a  2  s.c  o m*/

    mainFrame.setVisible(true);

}

From source file:Main.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setSize(400, 400);/*  w w  w  .ja va  2 s  .c  o m*/
    f.add(new Main());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:MainClass.java

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

    final JPanel p1 = new JPanel();
    p1.add(new JLabel("GlassPane Example"));
    JButton show = new JButton("Show");
    p1.add(show);/*from  w w  w  . j av a  2s. c o m*/
    p1.add(new JButton("No-op"));
    f.getContentPane().add(p1);

    final JPanel glass = (JPanel) f.getGlassPane();

    glass.setVisible(true);
    glass.setLayout(new GridBagLayout());
    JButton glassButton = new JButton("Hide");
    glass.add(glassButton);

    f.setSize(150, 80);
    f.setVisible(true);

    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(true);
            p1.repaint();
        }
    });
    glassButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            glass.setVisible(false);
            p1.repaint();
        }
    });
}