Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen resolution java code

Tags:

java

gwt

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");
like image 799
MindBrain Avatar asked Nov 04 '22 03:11

MindBrain


2 Answers

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.

like image 126
Adrian B. Avatar answered Nov 09 '22 16:11

Adrian B.


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.

like image 24
thermite Avatar answered Nov 09 '22 15:11

thermite