How to convert a JButton into JToggleButton in Java?

1 Yes, Netbeans support that functionality but as I had built those JButtons with the help of Netbeans GUI Builder, so the code for that GUI is Netbeans generated code which I can't edit. So, even if it supports find and replace all functionality, it won't be applicable in my situation. – Yatendra Goel Jan 18 '10 at 18:17.

Given that a JToggleButton is a button with two-states, chances are that your JButtons, which are single state, do not have actions that correctly handle two states. As a result, this will most likely not be nearly as easy as it seems like it should be (as in Anthony's response) or your UI will not make sense with the new buttons. What I would ask you is to think about the UI from two perspectives: Why are you switching all the JButtons to JToggleButtons?

Does this provide any advantage to the user interface that will help your users overall? Is there something that can be done better? You mentioned that you have "hundreds" of JButtons.

That makes me nervous when I hear that. Even for a fairly large application, that is a lot of buttons. This may mean your UI is cluttered and difficult to understand for a user.

Basically, think about why you are trying to do what you're trying to do. Is it really necessary? Is there something that could be an even better solution?

I know this isn't the exact answer you were looking for, but I hope it helps.

Ans1. Yes, switching from JButtons to JToggleButtons will provide more benefit to my end user so it is necessary to switch to JToggleButtons. For more details for why I want to switch, you can check out the reason at stackoverflow.Com/questions/2086355/… Ans 2.

Yes, my application is a fairly large application. As I have grouped those buttons into JPanels and not all the buttons are visible at a time, so the UI is not cluttered. Instead, it has a very clean look.

:) – Yatendra Goel Jan 18 '10 at 18:22.

Netbeans will define an xml file somewhere containing the GUI definition, including the JToggleButtons. I'd try doing a find-replace in this file and then reloading your project. Just make sure you take a back-up first!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions