List of usage examples for javax.swing JRootPane JRootPane
public JRootPane()
JRootPane
, setting up its glassPane
, layeredPane
, and contentPane
. From source file:org.eclipse.wb.internal.swing.preferences.laf.LafPreferencePage.java
/** * Creates {@link EmbeddedSwingComposite} with some Swing components to show it using different * LAFs.// w w w .j av a 2 s .c o m */ private void createPreviewArea(Group previewGroup) { try { LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel(); EmbeddedSwingComposite awtComposite = new EmbeddedSwingComposite(previewGroup, SWT.NONE) { @Override protected JComponent createSwingComponent() { // create the JRootPane JRootPane rootPane = new JRootPane(); { JMenuBar menuBar = new JMenuBar(); rootPane.setJMenuBar(menuBar); { JMenu mnFile = new JMenu(Messages.LafPreferencePage_previewFile); menuBar.add(mnFile); { JMenuItem mntmNew = new JMenuItem(Messages.LafPreferencePage_previewNew); mnFile.add(mntmNew); } { JMenuItem mntmExit = new JMenuItem(Messages.LafPreferencePage_previewExit); mnFile.add(mntmExit); } } { JMenu mnView = new JMenu(Messages.LafPreferencePage_previewView); menuBar.add(mnView); { JMenuItem mntmCommon = new JMenuItem(Messages.LafPreferencePage_previewCommon); mnView.add(mntmCommon); } } } GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0E-4 }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0E-4 }; rootPane.getContentPane().setLayout(gridBagLayout); { JLabel lblLabel = new JLabel(Messages.LafPreferencePage_previewLabel); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.gridx = 0; gbc.gridy = 0; rootPane.getContentPane().add(lblLabel, gbc); } { JButton btnPushButton = new JButton(Messages.LafPreferencePage_previewButton); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 0; rootPane.getContentPane().add(btnPushButton, gbc); } { JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] { Messages.LafPreferencePage_previewCombo, "ComboBox Item 1", "ComboBox Item 2" })); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 1; rootPane.getContentPane().add(comboBox, gbc); } { JRadioButton rdbtnRadioButton = new JRadioButton(Messages.LafPreferencePage_previewRadio); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 1; rootPane.getContentPane().add(rdbtnRadioButton, gbc); } { JCheckBox chckbxCheckbox = new JCheckBox(Messages.LafPreferencePage_previewCheck); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 5); gbc.gridx = 0; gbc.gridy = 2; rootPane.getContentPane().add(chckbxCheckbox, gbc); } { JTextField textField = new JTextField(); textField.setText(Messages.LafPreferencePage_previewTextField); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 1; gbc.gridy = 2; rootPane.getContentPane().add(textField, gbc); } return rootPane; } }; awtComposite.populate(); // restore current laf UIManager.put("ClassLoader", currentLookAndFeel.getClass().getClassLoader()); UIManager.setLookAndFeel(currentLookAndFeel); } catch (Throwable e) { DesignerPlugin.log(e); } }
From source file:org.geopublishing.atlasViewer.swing.ClickInfoDialog.java
/** * Since the registerKeyboardAction() method is part of the JComponent class * definition, you must define the Escape keystroke and register the * keyboard action with a JComponent, not with a JDialog. The JRootPane for * the JDialog serves as an excellent choice to associate the registration, * as this will always be visible. If you override the protected * createRootPane() method of JDialog, you can return your custom JRootPane * with the keystroke enabled:/*from w w w .ja v a 2s .c o m*/ */ @Override protected JRootPane createRootPane() { KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); JRootPane rootPane = new JRootPane(); rootPane.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rootPane; }