Java Utililty Methods JFrame

List of utility methods to do JFrame

Description

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

Method

voidsaveMainWindowLocation(JFrame jfrm, String strPropertiesFilePath, String strPropertiesFileName)
This method saves the main window location, size, and state to the properties file.
saveMainWindowLocation(jfrm, strPropertiesFilePath, strPropertiesFileName, null);
voidsetBlockAllUserInput(final JFrame frame, final boolean yesNo)
set Block All User Input
invokeAndWait(new Runnable() {
    @Override
    public void run() {
        frame.getGlassPane().setVisible(yesNo);
});
voidsetCursorFree(JFrame frame)
Set cursor to free and enable application input.
setCursorFree(frame.getRootPane().getGlassPane());
voidsetDialogLocation(JFrame frame, JFrame parentFrame)
Sets the dialogLocation attribute of the TapUtils class
Point location = new Point();
location.x = parentFrame.getLocation().x + parentFrame.getWidth() / 2 - frame.getWidth() / 2;
location.y = parentFrame.getLocation().y + parentFrame.getHeight() / 2 - frame.getHeight() / 2;
if (location.x < 0)
    location.x = 0;
if (location.y < 0)
    location.y = 0;
frame.setLocation(location);
...
voidsetDirty(JFrame frame, boolean isDirty)
set Dirty
setDirty(frame.getRootPane(), isDirty);
voidsetEscapeAction(JFrame frame, Action action)
Associate a custom action to be called when the Esc key is pressed.
setEscapeAction(frame.getRootPane(), action);
voidsetEscapeClosable(JFrame frame)
Make a dialog closeable by pressing the Esc key.
setEscapeAction(frame.getRootPane(), makeCloseAction(frame));
voidsetESCCloseable(final JFrame aFrame)
makes the JFrame closeable with ESC key.
KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Action escapeAction = new AbstractAction() {
    public void actionPerformed(ActionEvent ae) {
        aFrame.dispose();
};
aFrame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
aFrame.getRootPane().getActionMap().put("ESCAPE", escapeAction);
...
voidsetFrameBottomRight(final JFrame frame)
set Frame Bottom Right
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
int x = (int) rect.getMaxX() - frame.getWidth();
int y = (int) rect.getMaxY() - frame.getHeight();
frame.setLocation(x, y);
voidsetFramePositon(JFrame inTargetFrame)
set Frame Positon
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Dimension size = inTargetFrame.getSize();
if (d.width >= 640) {
    inTargetFrame.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
} else {
    inTargetFrame.setLocation(0, 0);
    inTargetFrame.setSize(d);