Blurry Image in JToggleButton
Hello, I have recently started developing a small application involving JToggleButtons. One of the goals of this application is to set the image of a JToggleButton to a certain image located in the same location as the application itself. I manage to load the image and using setIcon(), set it as the JToggleButton's icon, however, the image appears as though it has no saturation - it's all nearly black and white. Is there a good explanation why this is happening? If so is it possible to get around this?
With Thanks,
laginimaineb.
> Is there a good explanation why this is happening?None that I no of.[url http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html]How to Use Icons[/url].
I just found out why this is happening, however, instead of being happy, this is just annoying. I wanted my JToggleButtons to be clickable only once, and so after being clicked I set their status to disabled (setEnabled(false)), however, by doing this, apparently each image shown on the JToggleButton is far less saturated. This is a big setback, is there something I can do about it? (I can have a big array of boolean values telling me which buttons have already been clicked, however this seems a silly solution to a supposedly small problem).
With Thanks,
laginimaineb.
> I wanted my JToggleButtons to be clickable only once,
What if the user makes a mistake? How do you reset the button?
> (I can have a big array of boolean values telling me which buttons have already been clicked,
Well, presumably you do some kind of action when you click the button, so just remove the actionListener from the button.
First of all, the button is resettable using a different button (and believe me, it suits the context of the application). Secondly, I want to be able to know which button has been clicked and which hasn't for another part of my application. However, just decided to take the easy way out and set the actionCommand of the button to "Pressed" after it has been pressed, this way I can monitor pressed buttons. However, now I need a way to set the button to a permenant pressed status, is there such a thing?
With Thanks,
laginimaineb.
> now I need a way to set the button to a permenant pressed status
maybe this is all you need to do
(technically it won't be permanently pressed, but visually it will appear so)
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Testing extends JFrame
{
public Testing()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(250,75);
setLocation(400,300);
JPanel jp = new JPanel();
final JToggleButton tb = new JToggleButton("Click Me");
jp.add(tb);
getContentPane().add(jp);
tb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
tb.setSelected(true);//<--
}
});
}
public static void main(String args[]){new Testing().setVisible(true);}
}
Use setDisabledIcon, setDisabledSelectedIcon and other API of JToggleButton.
Michael, thanks a lot! This is all I was looking for... I didn't know about the setSelected method... I kept overlooking it. Thanks again.With Thanks,laginimaineb.