Solved

Example needed using JToggleButton

Posted on 1998-04-08
1
1,702 Views
Last Modified: 2008-02-01
I'm just starting using some of the Swing components and I was wondering how do I use the JToggleButton.  I'd like to have the button "toggle" between two icons.  Can anyone give me an example of how to do this?

Thanks in advance.
0
Comment
Question by:mwalker
1 Comment
 
LVL 1

Accepted Solution

by:
mnelson051997 earned 50 total points
ID: 1233996
If you have two GIFs and want one used when the button
is selected and the other used when it is not:

JToggleButton b = new JToggleButton( "text" );
b.setIcon( new ImageIcon( "up.gif" ) );
b.setSelectedIcon( new ImageIcon( "down.gif" ) );

Or, you can pass the "up.gif" icon to the constructor instead
of calling setIcon().
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 25
oracle 11g 23 73
login form jsp example 2 24
printf performancy 11 32
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

805 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