[英]Java Window Event - Maximize. How to hardcode?
I have a JDesktopPane and a JInternalFrame. 我有一个JDesktopPane和一个JInternalFrame。 I'd like the JInternalFrame to automatically maximize after I make it. 我希望JInternalFrame完成后自动最大化。 How can I hardcode the "maximize window" event? 如何对“最大化窗口”事件进行硬编码?
Use JInternalFrame.setMaximum(true)
after you create your frame. 创建框架后,请使用JInternalFrame.setMaximum(true)
。
Here is how you can maximize your frame: 这是最大化框架的方法:
JInternalFrame frame = ...
frame..setMaximum(true); // Maximize this window to fill up the whole desktop area
Setting the method setMaximum(boolean b) of JInternalFrame to "true" , will maximize it. 将JInternalFrame的 setMaximum(boolean b)方法设置为“ true”会使其最大化。
eg: 例如:
JInternalFrame.setMaximum(true)
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.