Example usage for javax.swing JFrame setVisible

List of usage examples for javax.swing JFrame setVisible

Introduction

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

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this Window depending on the value of parameter b .

Usage

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");

    jb.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
            System.out.println("ChangeEvent!");
        }//from   www .  jav a 2s .  c  om
    });
    jb.setText("new text");

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

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");

    jb.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
            System.out.println("ChangeEvent!");
        }/* w w w . jav  a2 s  .c  om*/
    });
    jb.setVerticalTextPosition(20);

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

From source file:CombiningShapes.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.add(new CombiningShapes());
    f.setSize(220, 220);/*w  w  w  .j a  v  a 2 s . com*/
    f.setVisible(true);
}

From source file:GraphicsDrawChars.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setSize(400, 400);//from w w w  .  j a  va2s  .c o  m
    f.add(new GraphicsDrawChars());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextArea comp = new JTextArea();
    String actionName = "Lowercase";

    JFrame f = new JFrame();
    f.add(new JScrollPane(comp));
    f.setSize(300, 300);/*w w w .  j av  a  2s . c  om*/
    f.setVisible(true);
    comp.getInputMap().put(KeyStroke.getKeyStroke("F2"), actionName);

    comp.getActionMap().put(actionName, new TextAction(actionName) {
        public void actionPerformed(ActionEvent evt) {
            JTextComponent comp = getTextComponent(evt);

            if (comp.getSelectionStart() == comp.getSelectionEnd()) {
                if (comp.getCaretPosition() < comp.getDocument().getLength()) {
                    try {
                        int pos = comp.getCaretPosition();
                        Document doc = comp.getDocument();
                        String str = doc.getText(pos, 1).toLowerCase();

                        doc.remove(pos, 1);
                        doc.insertString(pos, str, null);
                        comp.moveCaretPosition(pos + 1);
                    } catch (Exception e) {
                        System.out.println();
                    }
                }
            } else {
                int s = comp.getSelectionStart();
                int e = comp.getSelectionEnd();

                comp.replaceSelection(comp.getSelectedText().toLowerCase());
                comp.select(s, e);
            }
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new Main("javax.swing.JButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();/*  ww  w  .  j ava  2  s. c  o m*/
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) throws InterruptedException {
    JFrame frame = new JFrame();
    frame.add(new JLabel("Minimize demo"));
    frame.pack();//from w  w w .j a v a 2s. co m

    // Show the frame
    frame.setVisible(true);

    // Sleep for 5 seconds, then minimize
    Thread.sleep(5000);
    frame.setState(Frame.ICONIFIED);

    // Sleep for 5 seconds, then restore
    Thread.sleep(5000);
    frame.setState(Frame.NORMAL);

    // Sleep for 5 seconds, then kill window
    Thread.sleep(5000);
    frame.setVisible(false);
    frame.dispose();

    // Terminate test
    System.exit(0);
}

From source file:Slice.java

public static void main(String[] argv) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MyComponent());
    frame.setSize(300, 200);//from w w w . j  a va2 s .  c  om
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] a) {
    final JTextField textField = new JTextField(5);

    textField.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
        }//from   w w  w.  j  a va 2  s  . c o  m

        public void focusLost(FocusEvent e) {
            if (!e.isTemporary()) {
                String content = textField.getText();
                if (!content.equals("a")) {
                    System.out.println("illegal value! " + content);
                    SwingUtilities.invokeLater(new FocusGrabber(textField));
                }
            }
        }
    });
    JFrame frame = new JFrame();
    frame.add(textField, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new Main();
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.pack();/*from  w w w.ja v a  2 s .c  o m*/
    frame.setVisible(true);
}