Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (604)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  AWT Button Borders  (Read 2461 times)
0 Members and 1 Guest are viewing this topic.
Offline elias4444

Junior Devvie





« Posted 2004-04-20 17:58:07 »

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.

Offline D.t.O

Junior Devvie




Psych'd about Java Games


« Reply #1 - Posted 2004-04-20 18:11:43 »

:-/
Why don't you just use a JButton Wink?

Enjoy.
Regards,
     - D.t.O
Offline elias4444

Junior Devvie





« Reply #2 - Posted 2004-04-20 18:14:38 »

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.  :-/

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline D.t.O

Junior Devvie




Psych'd about Java Games


« Reply #3 - Posted 2004-04-20 18:15:21 »

Quote
Or, even better, how does the default AWT button paint method paint such beautiful, perfectly antialiased text?

Shouldn't that be in the source (usually, there is a src.zip in the java installation folder)?

Enjoy.
Regards,
     - D.t.O
Offline D.t.O

Junior Devvie




Psych'd about Java Games


« Reply #4 - Posted 2004-04-20 18:19:40 »

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.  :-/

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 Grin.
I'm not saying you shouldn't care about compatibility though Wink.

Enjoy.
Regards,
     - D.t.O
Offline elias4444

Junior Devvie





« Reply #5 - Posted 2004-04-20 18:22:11 »

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!

Offline D.t.O

Junior Devvie




Psych'd about Java Games


« Reply #6 - Posted 2004-04-20 18:25:25 »

You're welcome Smiley

Looks like you can change your 'Personal Text' now:
Quote
One of these days I'll get it

Enjoy.
Regards,
     - D.t.O
Offline javawillie

Junior Devvie




Hola, Paco.


« Reply #7 - Posted 2004-04-20 18:27:48 »

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

Junior Devvie





« Reply #8 - Posted 2004-04-20 18:32:04 »

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.

Offline javawillie

Junior Devvie




Hola, Paco.


« Reply #9 - Posted 2004-04-20 18:35:30 »

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.  :-)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline D.t.O

Junior Devvie




Psych'd about Java Games


« Reply #10 - Posted 2004-04-20 18:39:45 »

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.

Keep trying Wink

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

Enjoy.
Regards,
     - D.t.O
Offline tom
« Reply #11 - Posted 2004-04-20 19:08:11 »

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

Offline elias4444

Junior Devvie





« Reply #12 - Posted 2004-04-20 19:15:13 »

Ouch...headache...I think I just drank too much java.  Embarrassed

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?

Offline elias4444

Junior Devvie





« Reply #13 - Posted 2004-04-20 19:22:31 »

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??!!?

Offline tom
« Reply #14 - Posted 2004-04-20 19:56:05 »

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.

Offline elias4444

Junior Devvie





« Reply #15 - Posted 2004-04-20 20:00:43 »

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?

Offline tom
« Reply #16 - Posted 2004-04-20 21:21:42 »

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?

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.

Offline elias4444

Junior Devvie





« Reply #17 - Posted 2004-04-21 12:26:41 »

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.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Elsealabs (15 views)
2014-12-28 10:39:27

CopyableCougar4 (19 views)
2014-12-28 02:10:29

BurntPizza (24 views)
2014-12-27 22:38:51

Mr.CodeIt (14 views)
2014-12-27 04:03:04

TheDudeFromCI (19 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (58 views)
2014-12-15 09:26:44

Mr.CodeIt (47 views)
2014-12-14 19:50:38

BurntPizza (96 views)
2014-12-09 22:41:13

BurntPizza (115 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!