MindBrain
MindBrain

Reputation: 7768

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");

Upvotes: 5

Views: 5805

Answers (3)

Chloe
Chloe

Reputation: 26264

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)

Upvotes: 0

thermite
thermite

Reputation: 85

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.

Upvotes: 1

Adrian B.
Adrian B.

Reputation: 4363

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.

Upvotes: 1

Related Questions