Solved

Example needed using JToggleButton

Posted on 1998-04-08
1
1,712 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

690 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