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

voiderror(JFrame frame, String msg)
error
Object[] options = { "OK" };
JOptionPane.showOptionDialog(frame, msg, "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE,
        null, options, options[0]);
voidexitFullScreen(JFrame mainAppFrame)
exit Full Screen
mainAppFrame.dispose();
mainAppFrame.setUndecorated(fsFrameUndecorated);
mainAppFrame.setResizable(fsFrameResizable);
mainAppFrame.setSize(fsFrameSize);
mainAppFrame.setLocation(fsFrameLocation);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);
mainAppFrame.setVisible(true);
FilefileChooser(JFrame frame, boolean saveDialog, String windowName, String filterName, String filterExtension)
file Chooser
JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir"));
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setFileFilter(new FileNameExtensionFilter(filterName, filterExtension));
File file = null;
if (fileChooser.showDialog(frame, windowName) == JFileChooser.APPROVE_OPTION) {
    String ext = extension(fileChooser.getSelectedFile());
    String message = null;
    if (saveDialog)
...
FilefindFileOpen(JFrame frame, String ext, String desc)
find File Open
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new FileNameExtensionFilter(desc, ext));
if (chooser.showOpenDialog(frame) != JFileChooser.APPROVE_OPTION) {
    return null;
return chooser.getSelectedFile();
FilefindFileSave(JFrame frame, String ext, String desc)
find File Save
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new FileNameExtensionFilter(desc, ext));
if (chooser.showSaveDialog(frame) != JFileChooser.APPROVE_OPTION) {
    return null;
return getSelectedFileWithExtension(chooser);
JFramefindJFrame(Component c)
Locates the JFrame for the given component
if (c == null) {
    return null;
} else if (c instanceof RootPaneContainer) {
    return (JFrame) c;
} else {
    return findJFrame(c.getParent());
JFramefindJFrame(Component myComponent)
find J Frame
Component currentParent = myComponent;
JFrame myFrame = null;
while (currentParent != null) {
    if (currentParent instanceof JFrame) {
        myFrame = (JFrame) currentParent;
        break;
    currentParent = currentParent.getParent();
...
voidfitToDesktop(final JFrame frame)
fit To Desktop
final int minWidth = (int) Math.min(frame.getBounds().getWidth(), desktopBounds.getWidth());
final int minHeight = (int) Math.min(frame.getBounds().getHeight(), desktopBounds.getHeight());
frame.setSize(minWidth, minHeight);
voidfullScreen(JFrame window)
full Screen
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
screenSize.width = screenSize.width * 2 / 3;
screenSize.height = screenSize.height * 2 / 3;
window.setMinimumSize(screenSize);
window.setLocation(screenSize.width * 1 / 6, screenSize.height * 1 / 6);
window.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
voidfullScreenUsingMaximise(JFrame w)
full Screen Using Maximise
w.setExtendedState(Frame.MAXIMIZED_BOTH);
w.setAlwaysOnTop(true);