• Post Reply Bookmark Topic Watch Topic
  • New Topic

trouble with jbutton Icon

 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all .
i'm trying to make a background image to a jbutton and then put a text on it

but when i do put the icon on it, it puts the icon over the text and doesn't show the text ...
i also have a background image in the background (but i don't see it making a diffrence because i used lp)
here's a sample of what i did


any ideas ?
thanks to all the helpers
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An uncompilable code snippet isn't enough to detect a problem. You need to post an SSCCE <- link

Also, opaque, contentAreaFilled and borderPainted are true by default, so you don't gain anything by setting them true.

Are you aware of the setHorizontal/VerticalTextPosition(...) methods?
 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setHorizontal/VerticalTextPosition tried them with center but still no text shows

if i remove the seticon line it shows the text normaly (but no icon obviously )
my only guess is the icon comes above the text is that possible ? seems weird
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the add method. According to the tutorial/API of JLayeredPane for add() method:
void add(Component)
void add(Component, Object)
void add(Component, Object, int)

Add the specified component to the layered pane. The second argument, when present, is an Integer that indicates the layer. The third argument, when present, indicates the component's position within its layer. If you use the one-argument version of this method, the component is added to layer 0. If you use the one- or two-argument version of this method, the component is placed underneath all other components currently in the same layer.


It seems you are adding the component to layer 1 because of the "1". Try "0" or use the add(component) version.
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
twin yan wrote: setHorizontal/VerticalTextPosition tried them with center but still no text shows

if i remove the seticon line it shows the text normaly (but no icon obviously )
my only guess is the icon comes above the text is that possible ? seems weird

No, the Icon is always painted before the text. So where's that SSCCE?
 
Lukasz Jarocki
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just put your class here without any unnecessary methods.

EDIT:
For me this code works fine. I removed your unnecessary methods like setOpaque(true), and set HorizontalTextPostion. While a.png is that image then it produces . Button caption is visible.

 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot ,

did it

thanks to all the helpers
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!