List of usage examples for javax.swing JFrame getRootPane
@BeanProperty(bound = false, hidden = true, description = "the RootPane object for this frame.") public JRootPane getRootPane()
rootPane
object for this frame. From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Default Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); JPanel panel = new JPanel(); JButton defaultButton = new JButton("Default Button"); defaultButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand() + " selected"); }// w w w .j a va 2 s .com }); panel.add(defaultButton); JButton otherButton = new JButton("Other Button"); otherButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand() + " selected"); } }); 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:ActionButtonSample.java
public static void main(String args[]) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String command = actionEvent.getActionCommand(); System.out.println("Selected: " + command); }/*from ww w.j ava 2 s . c o m*/ }; Container content = frame.getContentPane(); content.setLayout(new GridLayout(2, 2)); JButton button1 = new JButton("Text Button"); button1.setMnemonic(KeyEvent.VK_B); button1.setActionCommand("First"); button1.addActionListener(actionListener); content.add(button1); Icon warnIcon = new ImageIcon("Warn.gif"); JButton button2 = new JButton(warnIcon); button2.setActionCommand("Second"); button2.addActionListener(actionListener); content.add(button2); JButton button3 = new JButton("Warning", warnIcon); button3.setActionCommand("Third"); button3.addActionListener(actionListener); content.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); button4.setActionCommand("Fourth"); button4.addActionListener(actionListener); content.add(button4); JRootPane rootPane = frame.getRootPane(); rootPane.setDefaultButton(button2); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
private static void doDisableActiveRenderingInEDT(final JFrame jFrame) { jFrame.getRootPane().setOpaque(true); jFrame.setFocusTraversalKeysEnabled(true); jFrame.setIgnoreRepaint(false);// w ww. ja v a2s. c o m doSetIgnoreRepaint(jFrame, false); }
From source file:Main.java
public static void associaTeclaAtalho(JFrame frame, Action action, String nomeAcao, String... atalhos) { associaTeclaAtalho(frame.getRootPane(), action, nomeAcao, atalhos); }
From source file:Main.java
public static void main_helper(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setSize(300, 300);//w w w .ja va 2 s . c om f.setUndecorated(true); f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); JPanel panel = new JPanel(); panel.setBackground(java.awt.Color.white); f.setContentPane(panel); MetalLookAndFeel.setCurrentTheme(new MyDefaultMetalTheme()); try { UIManager.setLookAndFeel(new MetalLookAndFeel()); } catch (Exception e) { e.printStackTrace(); } SwingUtilities.updateComponentTreeUI(f); f.setVisible(true); }
From source file:Main.java
public static void installEscapeCloseOperation(final JFrame dialog) { Action dispatchClosing = new AbstractAction() { public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }/* w ww .j a v a 2s. c om*/ }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY); root.getActionMap().put(ESCAPE_KEY, dispatchClosing); }
From source file:Main.java
public static void closeOnEscape(final JFrame frame) { KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false);/* www. j av a2 s. c o m*/ frame.dispose(); } }; JRootPane rootPane = frame.getRootPane(); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "ESCAPE"); rootPane.getActionMap().put("ESCAPE", actionListener); }
From source file:components.FrameDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from www . j av a 2 s. c o m*/ */ private static void createAndShowGUI() { //Use the Java look and feel. try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { } //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); //Instantiate the controlling class. JFrame frame = new JFrame("FrameDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. FrameDemo2 demo = new FrameDemo2(); //Add components to it. Container contentPane = frame.getContentPane(); contentPane.add(demo.createOptionControls(), BorderLayout.CENTER); contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END); frame.getRootPane().setDefaultButton(defaultButton); //Display the window. frame.pack(); frame.setLocationRelativeTo(null); //center it frame.setVisible(true); }
From source file:FrameDemo2.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *///w w w .j a v a 2 s . com private static void createAndShowGUI() { // Use the Java look and feel. try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { } // Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); // Instantiate the controlling class. JFrame frame = new JFrame("FrameDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. FrameDemo2 demo = new FrameDemo2(); // Add components to it. Container contentPane = frame.getContentPane(); contentPane.add(demo.createOptionControls(), BorderLayout.CENTER); contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END); frame.getRootPane().setDefaultButton(defaultButton); // Display the window. frame.pack(); frame.setLocationRelativeTo(null); // center it frame.setVisible(true); }
From source file:QandE.MyDemo3.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from w w w. j a va 2 s . c o m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); JButton b = new JButton("A button"); frame.getContentPane().add(BorderLayout.PAGE_END, b); frame.getRootPane().setDefaultButton(b); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }