Results 1 to 14 of 14
  1. #1
    Rtme is offline Member
    Join Date
    May 2011
    Posts
    11
    Rep Power
    0

    Question Hide a button but keep the image?

    Hi again... Yeah... I want to be able to do as the title says - or in other words, to use a icon as a button. Because I am making my own (Simple plain-text) Text editor, I want to use icons for the popular things (Bold, italics...) But I don't want the outline of the buttons (Eg I want it to look like a picture not a button with a picture on it...)

    If anybody knows how, I searched on Google but I couldn't think of how to phrase it...

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Can't you just set the border of the JButton to whatever you want? Or override whichever paint method paints the border (I'm too lazy to look it up.. paintBorder?). Or call setBorderPainted(false).

    All of these are in the JButton API.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Rtme is offline Member
    Join Date
    May 2011
    Posts
    11
    Rep Power
    0

    Default

    Setborderpainted(false) makes the border go away, but the button is still there, and I don't know what you mean by override whichever paint method paints the border...
    :confused:

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Setborderpainted(false) makes the border go away, but the button is still there,
    And that is what your question asked for. If you can't see the Border, then it just looks like a picture.

    Or you can always use a JLabel which doesn't have a Border by default

  5. #5
    Rtme is offline Member
    Join Date
    May 2011
    Posts
    11
    Rep Power
    0

    Default

    Yes, But what I Meant was to make the button disapear.

    And can JLabels get user input (Clicking) Because I diddn't think so...

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    If the button disappears, then the Icon disappears as well, so I don't understand what you are asking.

    A button is easier to use than a label because you can use an ActionListener. With a JLabel you need to add you own custom MouseListener to handle mouse events.

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Are you trying to get the background color of the JButton (surrounding the image) to disappear as well?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Rtme is offline Member
    Join Date
    May 2011
    Posts
    11
    Rep Power
    0

    Default

    I couldn't think how to explain, so I made this image: Dropbox - Photos - Simplify your life

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Many firewalls, including the one I'm behind right now, block sites like that. You could provide an SSCCE that demonstrates the problem.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Rtme is offline Member
    Join Date
    May 2011
    Posts
    11
    Rep Power
    0

    Lightbulb

    Nah, No matter on second thoughts what I want to do seems rather pointless...
    :)

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,407
    Rep Power
    20

    Default

    Read the API. The methods you want to use are inherited from AbstractButton. Look for methods like set...Painted(boolean)

    db

  12. #12
    asifzbaig is offline Member
    Join Date
    May 2011
    Posts
    56
    Rep Power
    0

    Default

    Hey I think i have your answer, i faced same problem in my project.

    What to do is to make a png icon with white or transparent background (if you have something about Corel and Adobe Illustrator), set the size of your button exactly or little less than your icon to make it fit in the button boundary than set the color of button and parent contaner same as your icon background..............

    Much of your problem will be sort out......

  13. #13
    Rtme is offline Member
    Join Date
    May 2011
    Posts
    11
    Rep Power
    0

    Default

    Ah, Thank you, Just what I wanted!

  14. #14
    asifzbaig is offline Member
    Join Date
    May 2011
    Posts
    56
    Rep Power
    0

    Default

    Thats all right, we all are here to get from others and do help to others.........

Similar Threads

  1. Make a button class that uses your button image.
    By eLancaster in forum New To Java
    Replies: 1
    Last Post: 04-26-2011, 11:32 AM
  2. button displays image
    By hopelessnoob in forum AWT / Swing
    Replies: 2
    Last Post: 03-12-2011, 03:44 PM
  3. AWT button image
    By timkd127 in forum AWT / Swing
    Replies: 2
    Last Post: 03-01-2010, 04:41 AM
  4. Set focus on image button in swt
    By diva_garg in forum New To Java
    Replies: 3
    Last Post: 08-18-2008, 12:27 PM
  5. Get Focus on Image button
    By diva_garg in forum SWT / JFace
    Replies: 0
    Last Post: 08-08-2008, 11:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •