The problem with Java Swing is the look and feels (Metal, Nimbus, GTK...), the worst out there compared to SWT, Windows, Mac and Gnome Tool Kit, and getting good looking widgets is utopist, yet I am asking the question though.
I need to know if there is a possibility to tweak a JButton to look like a default GTK button. Otherwise, can we give the JButton text a style (a shadow for example)?
public class myTweakedButton extends JButton {
// Override style attributes here.
}
Here is the style applied by GTK to the button widget:
style "button" {
xthickness = 3
ythickness = 3
bg[NORMAL] = shade (1.07, "#cdcdcd")
bg[PRELIGHT] = shade (1.09, "#cdcdcd")
bg[ACTIVE] = shade (1.0, "#cdcdcd")
bg[INSENSITIVE] = mix (0.25, @bg_color, "#e2e1e1")
fg[INSENSITIVE] = "#9c9c9c"
engine "murrine" {
#contrast = 1.0
border_shades = {1.04, 0.82}
reliefstyle = 5
shadow_shades = {1.02, 1.1}
textstyle = 1
glowstyle = 5
glow_shade = 1.1
#text_shade = 1.04
}
This is how a Button looks like when using the default GTK Look and Feel provided by Java engine:

And here how a button looks like under Linux (GTK 2.0).

The difference is actually a bad text hinting in Java GTK LAF, while GTK button text is styled with a discrete shadow.
there are two ways
but correct way (don't reinvent the wheel) use proper Look and Feel,
possible scenario
go to Insubstantial
download code source,
import all classes to the IDE (2-15 min depends of PC HardWare)
search for folder
test
, there isCheck.java
,run that and to try everything in
JMenu Look and Feel
, required download jar files for every goodCustom Java Swing Look and Feels
are accesible fromJMenu
nothing better around, all standard and good custom Swing's Look and Feel in one
JFrame
maybe better would be to use Substance together with SwingX, very good Custom implementation for Custom Swing, again nothing better around
NOTICE: SwingX required more than basic Swing knowledge, Substance (my view) required update and customize some methods in original code too
来源:https://stackoverflow.com/questions/10906889/can-we-ape-the-gtk-2-0-button-style-in-java-swing