Results 1 to 12 of 12
- 11-08-2012, 07:40 AM #1
Member
- Join Date
- Nov 2012
- Location
- Victoria, BC
- Posts
- 14
- Rep Power
- 0
- 11-09-2012, 05:08 PM #2
Re: How to make a resizable JFrame using a drop down list with different resolutons?
So you can set the size of a window at runtime by changing the preferred size of the top level component and then calling pack() on the container. What have you tried?
- 11-09-2012, 08:24 PM #3
Member
- Join Date
- Nov 2012
- Location
- Victoria, BC
- Posts
- 14
- Rep Power
- 0
Re: How to make a resizable JFrame using a drop down list with different resolutons?
top level component being the JFrame? I dont have any other components other than a canvas
- 11-09-2012, 09:19 PM #4
Re: How to make a resizable JFrame using a drop down list with different resolutons?
No, top level being the component you put in the jframe. You generally don't do much of anything to a jframe itself, rather, you put gui components in panels which reside in the JFrame. The top level JPanel would be the one you set the size on, and then you pack the JFrame.
- 11-09-2012, 10:40 PM #5
Member
- Join Date
- Nov 2012
- Location
- Victoria, BC
- Posts
- 14
- Rep Power
- 0
Re: How to make a resizable JFrame using a drop down list with different resolutons?
In my main method I am using:
Game game = new Game();
game.frame.add(game);
game.frame.pack();
the Game constructor is:
public Game() {
setPreferredSize(size);
frame = new JFrame();
}
the Game class extends Canvas implements Runnable
so I'm not using a panel or anything
- 11-12-2012, 04:01 PM #6
Re: How to make a resizable JFrame using a drop down list with different resolutons?
That might work because Canvas extends Component - but canvas is a leftover from the AWT days, and I usually try to avoid using non-swing stuff if possible. The technique I described might still work, but it would also be trivial to make your game extend JPanel instead of Canvas.
- 11-12-2012, 11:49 PM #7
Member
- Join Date
- Nov 2012
- Location
- Victoria, BC
- Posts
- 14
- Rep Power
- 0
Re: How to make a resizable JFrame using a drop down list with different resolutons?
Alright I got it to work. What I need now is to make it so it is fullscreen and borderless, no matter what the resolution is (so it will scale up to the monitor size)
- 11-13-2012, 02:33 PM #8
Re: How to make a resizable JFrame using a drop down list with different resolutons?
Thats not too hard to do - you do it through a series of calls which get the current graphics device and then set it's display mode. I use something like this boiler plate code:
The last line assumes the current class extends JFrame, but if your jFrame is separate, then just reference it there instead of 'this'. You can leave fullscreen by doing:Java Code:GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); GraphicsDevice gd = gs[0]; gd.setFullScreenWindow(this);
Java Code:gd.setFullScreenWindow(null);
- 11-13-2012, 02:34 PM #9
Re: How to make a resizable JFrame using a drop down list with different resolutons?
FYI, that code only makes the app occupy the entire screen, it does not change the resolution of the display. You probably don't want to do that anyway. Look at the API for GraphicsDevice for ways to find the current screen resolution so that you can use it in your environment!
- 11-13-2012, 08:29 PM #10
Member
- Join Date
- Nov 2012
- Location
- Victoria, BC
- Posts
- 14
- Rep Power
- 0
Re: How to make a resizable JFrame using a drop down list with different resolutons?
So to change the resolution of the fullscreen window, I actually have to change the resolution of the monitor?
- 11-13-2012, 09:10 PM #11
Member
- Join Date
- Nov 2012
- Location
- Victoria, BC
- Posts
- 14
- Rep Power
- 0
Re: How to make a resizable JFrame using a drop down list with different resolutons?
Alright I set it so it gets all the available DisplayModes for the display, and put them in a combo box using this:
Java Code:public Dimension defaultSize = getDefaultScreenSize(); public static DisplayMode[] DisplayModes = device.getDisplayModes();
For one, it doesn't include my monitors native resolution (the list starts at 1440x900 - my monitors native is 1600x900) even though i used:Java Code:for (int i = 0; i < DisplayModes.length; i++) { if(DisplayModes[i].getWidth() <= defaultSize.width && DisplayModes[i].getHeight() <= defaultSize.height) { cBox.addItem(DisplayModes[i]); } }
Also if its in certain resolutions it wont scale up to fit the monitor. 800x600 does, but 1280x720 wont.Java Code:if(DisplayModes[i].getWidth() <= defaultSize.width && DisplayModes[i].getHeight() <= defaultSize.height)
Another thing, how do I change the text of the combo box without changing what that selection does? The DisplayModes aren't readable.
- 11-14-2012, 07:48 PM #12
Re: How to make a resizable JFrame using a drop down list with different resolutons?
Depends on what you are trying to do. If you do not change the display resolution and your screen area is set to something small like 640x480, then the display window will just be a small viewport in the center of the screen with lots of black margin around it.So to change the resolution of the fullscreen window, I actually have to change the resolution of the monitor?
If your display resolution is the same size as the screen resolution, then making to go fullscreen will just display the viewport fullscreen, no borders.
If you want a small viewport like 640x480 to fill the entire screen on a large display, then the resolution of the display MUST be changed. You can do this programmatically by inspecting the list of supported resolutions on the GraphicsDevice and picking one that fits your needs. In order for your app to work fullscreen on many different monitors and setups, you'll need to support several common resolutions, usually in two or three different aspect ratios - 4:3 (traditional non-widescreen monitors and TVs), 16:9 (modern widescreen TVs and some monitors), 16:10 (most modern widescreen monitors).
Similar Threads
-
drop down list
By nour in forum AndroidReplies: 2Last Post: 11-20-2011, 09:25 PM -
what code for searching in drop down list?
By Harmesh Goyal in forum Advanced JavaReplies: 1Last Post: 03-03-2011, 04:43 AM -
Populating a drop down list from a database
By matpj in forum New To JavaReplies: 0Last Post: 01-19-2009, 12:14 PM -
JComboBox and drop-down list.....HELP!!!!!
By Anna in forum AWT / SwingReplies: 1Last Post: 06-18-2008, 05:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks