AWT Button Borders

OK, here’s a puzzle for all of you:

It’s easy to customize a JButton border…but how do you customize an AWT Button border without overriding the paint method?

See, here’s the problem:
I can override the paint method, but then the text on the button looks UGLY. I can add renderinghints and the like, but compared to the default AWT button text, it’s just ugly. I tried overriding the paint method, calling super first and then painting rectangles around the border, but when a popupmenu comes up, the repaint calls stop working for the buttons, and the borders come back.

So, can I customize an AWT button border? Or, even better, how does the default AWT button paint method paint such beautiful, perfectly antialiased text? If I knew that, I’d just override the whole thing and do it myself.

:-/
Why don’t you just use a JButton ;)?

One word: compatibility.

A second word: speed (although that really needs to be proven I think).

I originally wrote the app in swing, but have been trying to port it over to AWT in hope that it’ll work with older versions of java. :-/

[quote]Or, even better, how does the default AWT button paint method paint such beautiful, perfectly antialiased text?
[/quote]
Shouldn’t that be in the source (usually, there is a src.zip in the java installation folder)?

[quote]One word: compatibility.
[…]
I originally wrote the app in swing, but have been trying to port it over to AWT in hope that it’ll work with older versions of java. :-/
[/quote]
That certainly is a good idea. It just seems kind of weird on this forum, where people are already talking about the nanotimer in the beta of 1.5.0 ;D.
I’m not saying you shouldn’t care about compatibility though ;).

DOH! Whoa! Aei!

I had no idea that was ever there!

I suddenly feel empowered! I suddenly feel like everything is within my reach now!

I’m…I’m…(ok, better stop before I try flying out the third window in my underwear to save the day somewhere).

THANK YOU!

You’re welcome :slight_smile:

Looks like you can change your ‘Personal Text’ now:

[quote]One of these days I’ll get it
[/quote]

Can you use Java2D to do the anti-aliased text?

I actually had the same issue with Swing. You override the paint method, cast to Graphics2D, establish some rendering hints…but the text would just come out ugly. I’m actually reading through all the source code right now, trying to find how they antialias the text…I’m down to the Component.java source, but still no luck.

I’m not a pro on AWT/Swing stuff, so I’m just putting this out as an idea, but I wonder if the actual text rendering for AWT components is handled by the OS. After all AWT uses heavyweight OS peers to render the components (though I don’t know if the text is included in that).

Hopefully somebody with more AWT knowledge than me can clarify. :slight_smile:

[quote]I’m actually reading through all the source code right now, trying to find how they antialias the text…I’m down to the Component.java source, but still no luck.
[/quote]
Keep trying :wink:

javawillie, I’m not 100% sure either. If the OS handles anti-aliasing, we got a major problem with compatibility. :-/

If you wan’t to use antialiased text with java 1.1 (no swing or Java2D), then you have to render it yourself.

Ouch…headache…I think I just drank too much java. :-[

I’ve been sifting through the source code. I can’t seem to trace back where the actual painting of the label on the button is taking place…and actually, I can’t even find anything about the border either.

Can I have a hint?

Here’s where I’m stuck…

I found the awt folder, when in to button.java.
Saw that it doesn’t have a paint method, but extends component.java.
Went to component.java, which doesn’t extend anything, but who’s paint method is completely empty. Now, how does THAT work??!!?

It’s not painted in java. It’s done by a native method, wich uses the os to paint the button. Thats why they look different on different operating systems.

A couple of things:

I’m really starting to appreciate the customizability of Swing components here…Java has come a long ways.

If Java can render a font via the system, why can’t I render the font the same way after painting a custom component underneath it? Is there a way?

[quote]If Java can render a font via the system, why can’t I render the font the same way after painting a custom component underneath it?
[/quote]
What are you thinking of here? If it is java.awt.Button, then java do not render the text. It is done by the os.

You can draw antialiased text with Java2D. If you wan’t to stick to java 1.1 the you can use bitmap fonts.

I was just thinking that if the system can make a call to the OS at some point to render some text, can we make that same call after painting over the old stuff?

Maybe I’m tackling this the wrong way (wouldn’t be the first time). I typically use Java2D with addrenderinghints; it’s just that the text still doesn’t look all that great compared to the OS rendering (in windows or linux). There’s several types of renderinghints available, or maybe there’s even a better way to do it without them. So, what’s the best way to render anti-aliased (or just smoothed) text in java apps and applets? I just want to make sure my applications look professional.