I have a JDesktopPane and a JInternalFrame. I'd like the JInternalFrame to automatically maximize after I make it. How can I hardcode the "maximize window" event?
Asked
Active
Viewed 1,002 times
0
3 Answers
2
Use JInternalFrame.setMaximum(true)
after you create your frame.
Here is how you can maximize your frame:
JInternalFrame frame = ...
frame..setMaximum(true); // Maximize this window to fill up the whole desktop area

GETah
- 20,922
- 7
- 61
- 103
-
yes but I don't want the user to have to press the maximie button – CodeGuy Jul 06 '12 at 17:35
-
No no, this will maximize your frame automatically from code, no user interaction needed – GETah Jul 06 '12 at 17:40
1
Setting the method setMaximum(boolean b) of JInternalFrame to "true" , will maximize it.
eg:
JInternalFrame.setMaximum(true)

Kumar Vivek Mitra
- 33,294
- 6
- 48
- 75
1
- already suggested above: JInternalFrame#setMaximum(boolean)
- Another option: DesktopManager#maximizeFrame(JInternalFrame)
- a bit different behavior when JDesktopPane resized.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class JInternalFrameMaximumTest {
public JComponent makeUI() {
final JDesktopPane desktop = new JDesktopPane();
Action a1 = new AbstractAction("JInternalFrame#setMaximum") {
@Override public void actionPerformed(ActionEvent e) {
JInternalFrame f = new JInternalFrame("#",true,true,true,true);
desktop.add(f);
f.setVisible(true);
try {
f.setMaximum(true);
} catch(java.beans.PropertyVetoException ex) {
ex.printStackTrace();
}
}
};
Action a2 = new AbstractAction("DesktopManager#maximizeFrame(f)") {
@Override public void actionPerformed(ActionEvent e) {
JInternalFrame f = new JInternalFrame("#",true,true,true,true);
desktop.add(f);
f.setVisible(true);
desktop.getDesktopManager().maximizeFrame(f);
}
};
JToolBar toolbar = new JToolBar("toolbar");
toolbar.add(new JButton(a1));
toolbar.add(new JButton(a2));
JPanel p = new JPanel(new BorderLayout());
p.add(desktop);
p.add(toolbar, BorderLayout.NORTH);
return p;
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override public void run() {
createAndShowGUI();
}
});
}
public static void createAndShowGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new JInternalFrameMaximumTest().makeUI());
f.setSize(640, 240);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}

aterai
- 9,658
- 4
- 35
- 44