Java Utililty Methods JRootPane

List of utility methods to do JRootPane

  1. HOME
  2. Java
  3. J
  4. JRootPane

Description

The list of methods to do JRootPane are organized into topic(s).

Method

void addShortcut(JRootPane rootPane, String command, Action action)
add Shortcut
KeyStroke stroke = KeyStroke.getKeyStroke(command);
addShortcut(rootPane, command, action, stroke);
void closeOnEscape(final Window window, final JRootPane root)
Make the window close when the used presses escape.
InputMap map = root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), WINDOW_CLOSE);
Action dispatchClosing = new AbstractAction() {
 @Override
 public void actionPerformed(ActionEvent event) {
 window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
};
...
JRootPane getRootPane(Window window)
get Root Pane
if (window instanceof JFrame) {
 return ((JFrame) window).getRootPane();
if (window instanceof JDialog) {
 return ((JDialog) window).getRootPane();
return null;
void installEscapeBinding(final Window window, final JRootPane rootPane, final boolean dispose)
install Escape Binding
final KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE");
final InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(stroke, "ESCAPE");
rootPane.getActionMap().put("ESCAPE", new AbstractAction() {
 private static final long serialVersionUID = 1L;
 @Override
 public void actionPerformed(ActionEvent e) {
 if (dispose) {
...
boolean isSecondaryWindow(JRootPane rp)
is Secondary Window
Component c = rp.getParent();
if (c instanceof JInternalFrame) {
 return true;
} else {
 return false;
void makeWindowLeopardStyle(JRootPane rootPane)
Makes this window a Unified window on Mac OS X Leopard or greater systems.
if (rootPane.isValid()) {
 throw new IllegalArgumentException(
 "This method only works if the" + "given JRootPane has not yet been realized.");
rootPane.putClientProperty("apple.awt.brushMetalLook", Boolean.TRUE);
void registerEscapeAction(JRootPane pane, ActionListener l)
register key action when VK_ESCAPE pressed
KeyStroke keyStroke = KeyStroke.getKeyStroke((char) KeyEvent.VK_ESCAPE);
pane.registerKeyboardAction(l, keyStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
void setCancelAction(RootPaneContainer c, Action cancelAction)
Set up the escape keyboard shortcut for a JFrame or JDialog.
((JPanel) c.getContentPane()).getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
 .put(KeyStroke.getKeyStroke("ESCAPE"), "cancelAction");
((JPanel) c.getContentPane()).getActionMap().put("cancelAction", cancelAction);
void setEscapeAction(JRootPane pane, Action action)
Associate a custom action to be called when the Esc key is pressed.
pane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESC_KEYSTROKE, "ESCAPE");
pane.getActionMap().put("ESCAPE", action);


AltStyle によって変換されたページ (->オリジナル) /