简体   繁体   中英

Screen resolution java code

I would like to know how to fix the browser resolution for a pc of settings 1280X720 so that the web application developed in java using gwt doesnt looked stretched.I have tried

int width= windows.getClientWidth();
int height= windows.getClientHeight();
RootPanel.get().setHeight(height   + "px");
RootPanel.get().setWidth(width + "px");

You sure have some main component which is added to the RootPanel . A DockPanel or LayoutPanel or whatever you use as top component. Just fix the size of this panel and there you go. RootPanel.get() gives you a handle to the body element, changing the size of a sites body element does not make sense.

Ok I was looking into doing something along what you're looking into with a game I've been working on. And I found that there is a much better way to handle it. Once you get it worked out it will work with any resolution

example, I was trying to display items in an inventory. but with using integer values in the x, y for the images they would move around depending on what resolution the user was using.

so I baselined some x, y values like so

g.drawImage(inventory, width - 499, height / 2 - 20, null);
int ixt = width - 499;
int iyt = height / 2 - 20;
g.drawImage(broadsword, ixt + 10, iyt + 10, null);

this way it starts out at the 0,0 of the inventory image, and moves over and down 10 pixels and places the item image.

so no matter what resolution you'r in, it shows up in the same place every time.

Hopefully you can work something like that into your program.

You can change the browser size with

Window.resizeBy(500, 400);

however the window has to be opened with window.open .

http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/Window.html#resizeBy(int , int)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM