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

File[]inputFiles(JFrame argParent)
input Files
return inputFiles("Select a file...", argParent);
voidinstallEscapeCloseOperation(final JFrame dialog)
install Escape Close Operation
Action dispatchClosing = new AbstractAction() {
    public void actionPerformed(ActionEvent event) {
        dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
};
JRootPane root = dialog.getRootPane();
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY);
root.getActionMap().put(ESCAPE_KEY, dispatchClosing);
...
JInternalFrameinternalizeFrame(JFrame frame)
creates an internalized frame with the same title, size, menu bars and content pane
JInternalFrame ifr = new JInternalFrame(frame.getTitle(), true, true, true, true);
ifr.setSize(frame.getSize());
ifr.setContentPane(frame.getContentPane());
ifr.setJMenuBar(frame.getJMenuBar());
return ifr;
booleanisAv(JFrame frame)
is Av
try {
    final URL url = new URL(ROOT);
    final URLConnection con = url.openConnection();
    con.connect();
} catch (MalformedURLException e) {
    JOptionPane.showMessageDialog(frame, "Check Internet Connection");
} catch (IOException ex) {
    JOptionPane.showMessageDialog(frame, "Check Internet Connection");
...
booleanisVisibleNotMinimized(JFrame frame)
is Visible Not Minimized
assertEventDispatcherThread();
return (frame.isVisible() && frame.isShowing() && (frame.getExtendedState() & JFrame.ICONIFIED) == 0);
voidjointButton(JFrame frame, final JButton button)
Allows to relate a frame to a button
frame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent e) {
        button.setEnabled(true);
});
voidloadImageToFrame(JFrame frame, BufferedImage image)
This method is used for drawing an image to JFrame.
frame.setBounds(0, 0, image.getWidth(), image.getHeight());
frame.setVisible(true);
Graphics2D g = (Graphics2D) frame.getRootPane().getGraphics();
g.drawImage(image, null, 0, 0);
voidlocateForm(JFrame f, int x, int y, int w, int h)
Centra un frame e ne setta le dimensioni
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
x = (screenSize.width - w) / 2;
y = (screenSize.height - h) / 2;
f.setBounds(x, y, w, h);
voidmakeFullScreen(JFrame frame)
make Full Screen
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setUndecorated(true);
frame.setResizable(false);
voidmakeShaped(final JFrame frame)
make Shaped
if ("Mac OS X".equals(System.getProperty("os.name"))) {
    frame.setUndecorated(true);
    frame.setBackground(new java.awt.Color(0, 0, 0, 0));
    frame.getRootPane().putClientProperty("Window.shadow", Boolean.TRUE);
    frame.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
...