[solved] Toggling Swing Anti-Aliasing on the fly

Hey JGO, I’m trying to add onto my low quality gfx/high quality gfx buttons for my game and when I switch to low quality I’d like to disable anti-aliasing for certain swing components.

The code to disable it on the fly works as expected, but when I try to re-enable it using the same code but a boolean value of true this time it doesn’t update back to anti-aliasing?

First time using/hearing about this method so any help’s appreciated :slight_smile:

CODE:


// Obtain all the children of our frames content pane
for (Component e : GameWindow.frame.getContentPane().getComponents()) {

	// If it's a JButton (Trial)
	if (e instanceof JButton) {
		JButton source = (JButton) e;
							
		// Disable anti-aliasing.
		source.putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, false);	
	 
		// Show our changes.
		source.repaint();
	}
}

Why not have it on “high” (normal if you ask me) all the time?

Fiddling with Java :slight_smile:

Figured when enabling low quality, why render GUI components as fancy as possible?
Atleast disable anti-aliasing on components, keep fonts etc

I feel it gives the game a real low quality look :smiley:
Which is what I’m aiming for when this options toggled :3

Draw the components yourself? That’s what most games do any way, since they have a custom aesthetic.

For your problem specifically, are you updating the components on the EDT?

I don’t know how to obtain the Event Dispatching Thread if that’s what you’re referring to.

The code I posted above, is executed on a Thread(new Runnable()).

Is the EDT main-thread?

The EDT is not the “main” thread.

Easy way to run something on the EDT is [icode]SwingUtilities.invokeLater(new Runnable() {/* stuff */});[/icode]

I always seem to have a mouse position complication when drawing custom components via Graphics.

There’s always a offset when the mouse position is received so i basically have to hard-code placements and boundaries when making them.

Even when I do that I take into count users can have custom themes on their PC so me coding in hard-set positions wouldn’t be effective D:

Thank you :slight_smile:
That’s actually how I launch my gameThread XD

Will give it a try and post back.

OS themes have no effect on how your code displays.

By “draw them yourself” I meant create extensions of JComponent, then you can still use LayoutManagers and etc. with no “complications” or hard-coded layouts.

Putting your gameThread on the EDT doesn’t sound like a good idea.

Thanks :slight_smile:

But I chose the sexiest swing theme evar D:<
Is there a way I can simply over-ride rendering the button’s text and nothing else?

Thanks ^^
I remember doing it for a work-around for a Thread.sleep bug that was screwing with a JFrame of mine/game logic, I just started a new Thread ^
^

What do you mean by “override”? The font? That’s easy. Google it.
Also, if the theme isn’t WebLAF it’s not the sexiest. Jus’ saying.

JavaFX > Swing

By override I mean the method that actually renders the JButtons text.
(Obtain a Graphics context that is connected to rendering the text of the JButton so i can apply / remove RenderingHints)

I have a sexy font too :slight_smile: not what I meant by override.

I’ll be looking into WebLAF… :smiley:

The graphics context that renders the text is the same one that renders everything else.
Honestly JButton and most Swing components out-of-the-box aren’t suitable for games. Usually just a JLabel/custom component with an image that has the text on it + any mouseover/pressed effects pre-rendered is best.
WebLAF is similar, not for games, but unbeatable (in the Swing arena, JavaFX does seem to be better) for apps though. Check the demo.

Meh…
MyTheme + 1 (GraphiteLookAndFeel) :smiley:

Thanks for bringing it up though, some components/features do look smexy :3

I’ll do some testing and post back to see if I still need to look into this threads topic :smiley:

This thread left the tracks a while ago, but:

Most of this whole “UI Theme/Toolkit/etc” is pointless in the context of games anyway since you aren’t making a word processor or an email client. Most of what the game is (at least should be) is not GUI components, unless of course it’s some kind of “design a GUI” game… :persecutioncomplex:

Dropping this idea in my game >_<

Thanks to those who helped me on this thread :slight_smile: