MigLayout:尝试全屏时仅显示窗口
下面是代码:
ScreenHeight = Toolkit.getDefaultToolkit().getScreenSize().height,
ScreenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
JFrame MainFrame = new JFrame();
MainFrame.setSize(ScreenWidth, ScreenHeight);
MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
MainFrame.setVisible(true);
/* When set to false, all buttons and boxes are displayed,
otherwise only the main window appears */
MainFrame.setUndecorated(true);
Container Pane = Frame.getContentPane();
Pane.setLayout(new MigLayout());
initLoginPanel(Pane);
布局控件的函数:
private void initLoginPanel(Container Obj)
{
JPanel LoginContainer = new JPanel();
LoginContainer.setLayout(new MigLayout());
Obj.add(LoginContainer, "pos 0.5al 0.5al");
JLabel uNameLabel = new JLabel("Username");
JTextField uNameBox = new JTextField();
JLabel uPassLabel = new JLabel("Password");
JTextField uPassBox = new JTextField();
JButton LoginButton = new JButton("Login", 90, 26);
LoginContainer.add(uNameLabel, "wrap");
LoginContainer.add(uNameBox, "span");
LoginContainer.add(uPassLabel, "wrap");
LoginContainer.add(uPassBox, "span");
LoginContainer.add(LoginButton, "");
}
如果在上面的代码中使用 MainFrame.setUndecorated(false)
,它可以正常工作,但不能全屏。那就是标题栏,显示关闭、最小化和最大化按钮。
问题: 1. 如何让组件在全屏模式下工作。
Here is code:
ScreenHeight = Toolkit.getDefaultToolkit().getScreenSize().height,
ScreenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
JFrame MainFrame = new JFrame();
MainFrame.setSize(ScreenWidth, ScreenHeight);
MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
MainFrame.setVisible(true);
/* When set to false, all buttons and boxes are displayed,
otherwise only the main window appears */
MainFrame.setUndecorated(true);
Container Pane = Frame.getContentPane();
Pane.setLayout(new MigLayout());
initLoginPanel(Pane);
The function that lays out the controls:
private void initLoginPanel(Container Obj)
{
JPanel LoginContainer = new JPanel();
LoginContainer.setLayout(new MigLayout());
Obj.add(LoginContainer, "pos 0.5al 0.5al");
JLabel uNameLabel = new JLabel("Username");
JTextField uNameBox = new JTextField();
JLabel uPassLabel = new JLabel("Password");
JTextField uPassBox = new JTextField();
JButton LoginButton = new JButton("Login", 90, 26);
LoginContainer.add(uNameLabel, "wrap");
LoginContainer.add(uNameBox, "span");
LoginContainer.add(uPassLabel, "wrap");
LoginContainer.add(uPassBox, "span");
LoginContainer.add(LoginButton, "");
}
If, in the above code, MainFrame.setUndecorated(false)
is used, it works fine but no full screen. That is the title bar, close, minimize and maximize buttons are displayed.
Question:
1. How can I get the components working in fullscreen mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两个问题:
显示框架必须是最后一步;
首先,您必须设置您的框架并添加他的内容。
调用
initLoginPanel
您的代码正在做不正确的事情。为什么不直接将组件添加到框架中?即
固定、简化的代码:
There are two problems:
setVisible
Showing the frame must be the last step;
first you must setup your frame and add his content.
The call to
initLoginPanel
Your code is doing incorrect things. Why don't you add the components directly to the frame? i.e.
Fixed, simplified code: