Jump to content

User changed window size in Java

Go to solution Solved by fletch to 99,

If I'm understanding this right, you don't want the window to be resizable but you want to be able to use hardcoded sizes? Or were you looking for like a fullscreen option?

	public void init() {		this.setResizable(false);		/*		 * Create your jframe 		 */	}	public void onSizeChange(JComboBox box) {		switch (box.getSelectedIndex()) {		case 0:			this.setSize(100, 100);		case 1:			this.setSize(200, 200);		}	}

I made an options menu for a 2D java game that me and a few friends are working on, and I've been trying to figure out a way to get the application window to change sizes when you change the size in the options menu. I plan to set up a Flat File, but I need to find a way to be able to take the users input ( a combo box I have ), and have it actually affect the window size. ( I do have a change listener for the combo box, and set it to a variable )

 

I can post some code, or screen shots if they're required, but I really would just like a nice reference source, or some kind of example of this in action, since searching around on Google hasn't really helped me.

THANK YOU IN ADVANCE FOR ANY HELP!

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to comment
https://linustechtips.com/topic/67181-user-changed-window-size-in-java/
Share on other sites

Link to post
Share on other sites

If I'm understanding this right, you don't want the window to be resizable but you want to be able to use hardcoded sizes? Or were you looking for like a fullscreen option?

	public void init() {		this.setResizable(false);		/*		 * Create your jframe 		 */	}	public void onSizeChange(JComboBox box) {		switch (box.getSelectedIndex()) {		case 0:			this.setSize(100, 100);		case 1:			this.setSize(200, 200);		}	}

There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites

I selected the wrong one...





			
		

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to post
Share on other sites

 

If I'm understanding this right, you don't want the window to be resizable but you want to be able to use hardcoded sizes? Or were you looking for like a fullscreen option?

	public void init() {		this.setResizable(false);		/*		 * Create your jframe 		 */	}	public void onSizeChange(JComboBox box) {		switch (box.getSelectedIndex()) {		case 0:			this.setSize(100, 100);		case 1:			this.setSize(200, 200);		}	}

This should work thank you

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to post
Share on other sites

i figured :P

Sorry about that, I was eating some Ramen noodles whilst browsing the forums, so my awesome clicking skills were a bit off.

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to post
Share on other sites

Edit: I made a gamemaker a while back and threw it on github. It may interest you, you can use some of the concepts that power it if you wish. https://github.com/fletchto99/GameMaker

 

Edit 2: Here are some sample games I've made for it. https://github.com/fletchto99/GameMaker-Sample-Games

 

Also if your ever interested in fullscreen use this here:

	private boolean fullScreenMode = false;	public boolean isFullScreenMode() {		return fullScreenMode;	}	public void changeFullScreenMode() {		final GraphicsDevice device = getGraphicsConfiguration().getDevice();		if (!device.isFullScreenSupported()) {			return;		}		fullScreenMode = !fullScreenMode;		super.dispose();		if (fullScreenMode) {			setUndecorated(true);			device.setFullScreenWindow(this);		} else {			setUndecorated(false);			device.setFullScreenWindow(null);		}		setVisible(true);	}

There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites

 

Also if your ever interested in fullscreen use this here:

	private boolean fullScreenMode = false;	public boolean isFullScreenMode() {		return fullScreenMode;	}	public void changeFullScreenMode() {		final GraphicsDevice device = getGraphicsConfiguration().getDevice();		if (!device.isFullScreenSupported()) {			return;		}		fullScreenMode = !fullScreenMode;		super.dispose();		if (fullScreenMode) {			setUndecorated(true);			device.setFullScreenWindow(this);		} else {			setUndecorated(false);			device.setFullScreenWindow(null);		}		setVisible(true);	}

Thanks man, that's one less thing I'll have to spend a bunch of time playing around to get to work with no luck. xD

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to post
Share on other sites

Thanks man, that's one less thing I'll have to spend a bunch of time playing around to get to work with no luck. xD

 

Yup np :) -- Be sure to look at the edits I put in my previous post. I'm sure you will find some stuff you will like there.

There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites

Yup np :) -- Be sure to look at the edits I put in my previous post. I'm sure you will find some stuff you will like there.

Definitely really awesome, but I can't seem to get the games from the source to show up in the games manger for some reason. I have all of it set up in the same project, and no errors on anything, and it all looks good, but for whatever reason they don't show up on the menu. I can only assume there's some way I don't know of to set it up? 

 

PS: This is really awesome though, I plan to read through all this code, and figure it out tonight.

"Her tsundere ratio is 8:2. So don't think you could see her dere side so easily."


Planing to make you debut here on the forums? Read Me First!


unofficial LTT Anime Club Heaven Society

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×