handling picture within a frame

Posted on 2004-11-01
Last Modified: 2010-03-31
how can i show and hide a picture(like a tringle which contain an exclamation mark)
in a frame which contains a group of radiobutton at selecting
one of these radiobutton.
the symbol must be shown in front of the radiobutton.

Question by:kimo100
    LVL 9

    Expert Comment

    Use a JLabel to add the image to the screen, OR a JButton, here's an example:

    ImageIcon imgIc = new ImageIcon( "image.gif" );
    JButton jb = new JButton( imgIc );
    jb.setSize( x, y );
    jb.setBorderPainted( false );

    Then, when they select the radiobutton, it gets the image name from an array, and uses this to replace it:

    imgIc = new ImageIcon( "NewImage.gif" );
    jb = new JButton( imgIc );


    I think that should do it -- what do you think?? :-)
    LVL 9

    Expert Comment


    >"the symbol must be shown in front of the radiobutton."
    ...what do you mean by this exactly? :o\

    LVL 24

    Accepted Solution

    You can add the picture to the radiobutton, by  .setIcon(Icon) or by creating the RadioButton(Icon),
    ans set it in front by .setHorizontalAlignment(SwingConstants.*);
    LVL 9

    Expert Comment

    Hi V,
    to save you the decission; award sciuriware with the points, please. :-)

    LVL 24

    Expert Comment

    I'm honoured.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    1. Package the applet into a JAR file. The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a codebase attribute in  tag, replace the codebase …
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now