• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reduce gap between image and button

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have displayed a button with a image on it.
there is gap between actual image and button
I have to reduce the gap between the image and the button.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know. You would have to provide more details, about how you are locating the Components, layout manager used, etc.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How have you added the icon to the button? Using the button's setIcon method? If so, check out the API of JButton's parent, AbstractButton. Look at the setXXX methods, there is one you want to look at.
 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my app, there is a image which is of round shape. When i display that image on the button I want remaining area of the button should be transparent. is it possible
 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done,

JButton longButton = new JButton(new ImageIcon("c:/normal.png"));
longButton.setPressedIcon(new ImageIcon("c:/normalpress.png"));
longButton.setOpaque(false);
longButton.setBorderPainted(false);
longButton.setFocusPainted(false);
longButton.setBorder(new EmptyBorder(0,0,0,0));
longButton.setBackground(Color.blue);

following code, still I get the pressed look after pressing the button.

I dont want that effect which came after pressing the button (button is in pressed state)
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I dont want that effect which came after pressing the button (button is in pressed state)



That is not what your first question asked. We are not mind readers.

The pressing effect is caused by the Border, so get rid of the Border on the button.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

swapnel surade wrote:I have done,

JButton longButton = new JButton(new ImageIcon("c:/normal.png"));
longButton.setPressedIcon(new ImageIcon("c:/normalpress.png"));
longButton.setOpaque(false);
longButton.setBorderPainted(false);
longButton.setFocusPainted(false);
longButton.setBorder(new EmptyBorder(0,0,0,0));
longButton.setBackground(Color.blue);

following code, still I get the pressed look after pressing the button.

I dont want that effect which came after pressing the button (button is in pressed state)



First of all, pressing the button will cause the icon to change from normal.png to normalpress.png. If you don't want pressing the button to do that, then you shouldn't be calling setPressedIcon() [or you should set the pressed icon to the same as unpressed]. So I presume that's not what you are asking.

If normal.png and normalpress.png are the same size and have no transparent pixels, then I don't understand how you would see any "effect which came after pressing the button" since you have gone to the unusual step of replacing the button's border.
If they are different sizes or normalpress.png has transparent pixels, then you will probably (depending on your LnF) see the background color change. You should be able to disable this by calling longButton.setContentAreaFilled(false).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic