• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make some buttons to act like push down , push up ... buttons  RSS feed

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post.
sorry if my post title is not good enough , i am not english.
In one of my frames i need to have some buttons , for example
there are 4 buttons like : stop , start, next , prev .
I wan to be able to do the following , but i do not know whether there
are standard component for this kind of common requirement in swing or not.

when user press Start , all buttons should become disable and start should stay down.
start will be down until user press stop (stop is like ordinary Jbutton and do not stay down)
after user press stop , start button will come up and all other buttons will become enable.


now my question is : How i can do this ?


Thank you.
 
Palash Ray
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use javax.swing.JToggleButton instead of the usual JButton
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

if you want to inactive or active a button call the following after pressing a button

public void buttonsAfterPressingStartButton(){
northButton.setEnabled(true); // or false
eastButton.setEnabled(true);
southButton.setEnabled(true);
westButton.setEnabled(true);

this method should be called via an actionListner on your startButton.
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
So there is no feature in the swing component like :
component index, ... that determine some butons are in same group and if one of them goes down all other in the group come up ?


Thank you
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There might be, you could experiment with putting buttons in

//
public class ButtonGroup
extends Object
implements Serializable

This class is used to create a multiple-exclusion scope for a set of buttons. Creating a set of buttons with the same ButtonGroup object means that turning "on" one of those buttons turns off all other buttons in the group.
//

but I think you could do all you wanted by a series of methods called at the appropriate time, for example in my own implementation


public void buttonsAfterSecondCrop(){
northButton.setEnabled(true);
eastButton.setEnabled(true);
eastButton10.setEnabled(true);
southButton.setEnabled(true);
westButton.setEnabled(true);
westButton10.setEnabled(true);
OKButton.setEnabled(true);
if(isTwoSplit){
copyButton.setEnabled(false);
}
//leave blank for now
else if(isThreeSplit){
//prevents copybutton being pressed until OKbutton pressed
//this is so the user can align his second Roi
copyButton.setEnabled(false);
}
}

public void buttonsAfterOK(){
northButton.setEnabled(false);
eastButton.setEnabled(false);
eastButton10.setEnabled(false);
southButton.setEnabled(false);
westButton.setEnabled(false);
westButton10.setEnabled(false);
if(isTwoSplit){
copyButton.setEnabled(false);
saveButton.setEnabled(true);
OKButton.setEnabled(false);
}
//leave blank for now
else if(isThreeSplit && copyCount == ONE_IMAGE_CROPPED){
copyButton.setEnabled(true);
saveButton.setEnabled(false);
OKButton.setEnabled(false);
}
else if(isThreeSplit && copyCount == TWO_IMAGES_CROPPED){
copyButton.setEnabled(false);
saveButton.setEnabled(false);
OKButton.setEnabled(false);
}
}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!