Example usage for javax.swing JFrame getRootPane

List of usage examples for javax.swing JFrame getRootPane

Introduction

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

Prototype

@BeanProperty(bound = false, hidden = true, description = "the RootPane object for this frame.")
public JRootPane getRootPane() 

Source Link

Document

Returns the rootPane object for this frame.

Usage

From source file:Main.java

public static void main(String[] args) {
    String subject[] = { "Math", " English", "SQL", "   java", "  c ", " c++ ", " cobol ", "this is a test" };
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList<String> list = new JList<String>(subject);
    JScrollPane s = new JScrollPane(list);
    s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    f.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
    f.add(s);//from www.j a  va2s .co m
    f.setSize(300, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("Ancestor Sampler");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    AncestorListener ancestorListener = new AncestorListener() {
        public void ancestorAdded(AncestorEvent ancestorEvent) {
            System.out.println("Added");
        }/* w  w  w .ja va  2 s.  co m*/

        public void ancestorMoved(AncestorEvent ancestorEvent) {
            System.out.println("Moved");
        }

        public void ancestorRemoved(AncestorEvent ancestorEvent) {
            System.out.println("Removed");
        }
    };
    f.getRootPane().addAncestorListener(ancestorListener);
    f.getRootPane().setVisible(false);
    f.getRootPane().setVisible(true);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:MainClass.java

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

    AncestorListener ancestorListener = new AncestorListener() {
        public void ancestorAdded(AncestorEvent ancestorEvent) {
            System.out.println("Added");
        }/*  ww  w.  ja v  a2 s .  c  o m*/

        public void ancestorMoved(AncestorEvent ancestorEvent) {
            System.out.println("Moved");
        }

        public void ancestorRemoved(AncestorEvent ancestorEvent) {
            System.out.println("Removed");
        }
    };
    frame.getRootPane().addAncestorListener(ancestorListener);
    frame.setSize(300, 200);
    frame.setVisible(true);
    frame.getRootPane().setVisible(false);
    frame.getRootPane().setVisible(true);
}

From source file:Main.java

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

    frame.setLayout(new BorderLayout());
    frame.add(new JLabel("Hit Escape to exit full screen", JLabel.CENTER), BorderLayout.CENTER);

    frame.setSize(300, 300);//ww w .j a v a 2 s . c o m

    KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke("ESCAPE");
    Action escapeAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .setFullScreenWindow(null);
        }
    };

    frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
    frame.getRootPane().getActionMap().put("ESCAPE", escapeAction);

    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);

}

From source file:MainClass.java

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

    frame.setLayout(new GridLayout(2, 2, 10, 10));

    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    frame.add(button1);/*from   ww  w.j  ava  2  s  .  c o  m*/

    JButton button2 = new JButton("warn");
    frame.add(button2);

    JButton button3 = new JButton("Warning");
    frame.add(button3);

    String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
            + "<font color=\"#FF0080\"><u>Multi-line</u></font>";
    JButton button4 = new JButton(htmlButton);
    frame.add(button4);

    JRootPane rootPane = frame.getRootPane();
    rootPane.setDefaultButton(button2);

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

From source file:Main.java

public static void main(String args[]) {
    JPanel JMainPanel = new JPanel(new BorderLayout());
    JPanel jp = new JPanel();
    JComboBox combo = new JComboBox(new String[] { "Item1", "Item2", "Item3" });
    JPanel jImage = new JPanel();
    JFrame jf = new JFrame();

    jp.add(combo);/*from w  w  w  .j a  v a 2s. co m*/
    JMainPanel.add(jp, BorderLayout.WEST);
    JMainPanel.add(jImage, BorderLayout.CENTER);
    jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_DOWN_MASK), "screenshot");
    jp.getActionMap().put("screenshot", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            final BufferedImage bf = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    jf.getRootPane().paint(bf.getGraphics());
                    jImage.getGraphics().drawImage(bf, 0, 0, jImage);
                }
            });
        }
    });
    jf.getContentPane().add(JMainPanel);
    jf.setSize(500, 500);
    jf.setVisible(true);
}

From source file:PassiveTextField.java

public static void main(String[] args) {
    try {/*from w ww  .  j  a v a2  s.c o  m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new JFrame("Passive Text Field");
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    final PassiveTextField ptf = new PassiveTextField(32);
    JTextField tf = new JTextField(32);
    JPanel p = new JPanel();
    JButton b = new JButton("OK");
    p.add(b);
    f.getContentPane().add(ptf);
    f.getContentPane().add(tf);
    f.getContentPane().add(p);

    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Action event from a text field");
        }
    };
    ptf.addActionListener(l);
    tf.addActionListener(l);

    // Make the button the default button
    f.getRootPane().setDefaultButton(b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Content of text field: <" + ptf.getText() + ">");
        }
    });
    f.pack();
    f.setVisible(true);
}

From source file:PassiveTextField1.java

public static void main(String[] args) {
    JFrame f = new JFrame("Passive Text Field");
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    final JTextField ptf = new JTextField(32);
    JTextField tf = new JTextField(32);
    JPanel p = new JPanel();
    JButton b = new JButton("OK");
    p.add(b);/*www. ja  v a2s.  c  o  m*/
    f.getContentPane().add(ptf);
    f.getContentPane().add(tf);
    f.getContentPane().add(p);

    Keymap map = ptf.getKeymap(); // Gets the shared map
    KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    map.removeKeyStrokeBinding(key);

    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Action event from a text field");
        }
    };
    ptf.addActionListener(l);
    tf.addActionListener(l);

    // Make the button the default button
    f.getRootPane().setDefaultButton(b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Content of text field: <" + ptf.getText() + ">");
        }
    });
    f.pack();
    f.setVisible(true);
}

From source file:DefaultSample.java

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

    JTextField textField = new JTextField();
    frame.add(textField, BorderLayout.NORTH);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent.getActionCommand() + " selected");
        }/*from   w  ww.  ja v  a2 s.c om*/
    };
    JPanel panel = new JPanel();
    JButton defaultButton = new JButton("Default Button");
    defaultButton.addActionListener(actionListener);
    panel.add(defaultButton);

    JButton otherButton = new JButton("Other Button");
    otherButton.addActionListener(actionListener);
    panel.add(otherButton);

    frame.add(panel, BorderLayout.SOUTH);

    Keymap keymap = textField.getKeymap();
    KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    keymap.removeKeyStrokeBinding(keystroke);

    frame.getRootPane().setDefaultButton(defaultButton);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:DefaultSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Default Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();

    JTextField textField = new JTextField();
    content.add(textField, BorderLayout.NORTH);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent.getActionCommand() + " selected");
        }/*from  w  w  w. j  av a  2  s .c  om*/
    };

    JPanel panel = new JPanel();
    JButton defaultButton = new JButton("Default Button");
    defaultButton.addActionListener(actionListener);
    panel.add(defaultButton);

    JButton otherButton = new JButton("Other Button");
    otherButton.addActionListener(actionListener);
    panel.add(otherButton);

    content.add(panel, BorderLayout.SOUTH);

    Keymap keymap = textField.getKeymap();
    KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    keymap.removeKeyStrokeBinding(keystroke);

    frame.getRootPane().setDefaultButton(defaultButton);

    frame.setSize(250, 150);
    frame.setVisible(true);
}