java如何设置网页全屏,如何输出的Java全屏正常

Now what I am doing in my program is that I am using setundecorated = true and MAXIMIZED_BOTH So it makes it go full screen and the display looks very nice, But the problem is that there are images (border) on the left and the right side of my screen and also a blue background. What happens is that in changing screens and resolutions these get disturbed and are not shown properly. Those grey patches come up again

RGLmc.png

History:

I have a java program which I wanted to always open in full screen; I was not able to find a way to do it properly so I had adjusted the minimum to (1370, 727) and maximum size. Thus, it started opening properly on my laptop, but when I changed my laptop's display to LCD, it started giving problems:

It opens in a smaller window:

DjxDj.jpg

If I then click on the maximize button, a grey area comes on the side and bottom (I wanted the items on screen to get stretched or center themselves):

fqgRf.jpg

And here for example, there is a grey patch at the bottom. Instead, I want the background to cover the whole screen.

GgVXm.png

Update 1

If I change to stretchable gridbaglayout, this is the code I used and what happens:

Menu.setExtendedState(MAXIMIZED_BOTH);

GridBagLayout gbl = new GridBagLayout();

Menu.setLayout(gbl);

JButton component = new JButton("1");

gbl.layoutContainer(Menu);

GridBagConstraints gbc = new GridBagConstraints();

gbc.fill = GridBagConstraints.NONE;

gbl.setConstraints(component, gbc);

Menu.add(component);

Menu.pack();

Menu.setVisible(true);

EBrZJ.png

Question

How do I set "this" frame to setExtendedState(MAXIMIZED_BOTH) as I have done to others? (if I do this in main function, I get an error; even if I make a function for this and call it in main I get an error)

How do I get everything to stretch/rearrange themselves according to the extra grey space?

Update 2

My files in this project:

PTm2S.png

Update 3

This is the current file I am working on "FormTTS.java"

Search for "MAXIMIZED_BOTH" in there and you will find the code I think you will want to check.

解决方案

Usually, as far as games go, it's preferable to use full screen mode instead of using a maximized window. You can do this in Java by using:

GraphicsEnvironment gfxEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice gfxDev = gfxEnv.getDefaultScreenDevice();

Window window = new GameWindow();

gfxDev.setFullScreenWindow(window);

If you still want to use a regular frame and center the content panel, you need to define some of the GridBagLayout constraints. It's impossible to tell which without out seeing the code for the rest of the components on that screen, but consider the following:

GridBagConstraints.fill

GridBagConstraints.anchor

GridBagConstraints.weightx

GridBagConstraints.weighty

And finally, regarding setting the screen to the largest size, it is already addressed here:

Java JFrame Size according to screen resolution

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值