Button Logic

I have a Remove button on my base dialog.  The action of the button is to remove a selected row from my jtable.  So if there is not any objects in the my jtable the button should be grayed out or invisible - I don't care which.  So I created some logic around the button to see if there are are in objects in the table.

      if(checkList > 0){

I want to start the button out not there or not enabled in case there are no data in the table.  This works.  So now the user can add objects to the ArrayList in which updates the table.  So now I have a object in the table and the button is not enabled.  I can close the dialog and reopen it and it is fine.  

How do I let the button know that there has been a change to the jtable and to check the logic again?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In the same routine that fires TableModel events, check the state of your underlying Collection and en/disable the button accordingly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
In the same place where your program adds a line to your table - enable / dsable the button. And it does not matter that it may happen in different class. Have a methiod in your original class (with the button) wqhich would enable/disable the button, pass the handle to that class to any other class where it is necessary and use. This handle to invoke the enable/disable button of the original class. Make sure that your button is an instance vraiable of course
jkteaterAuthor Commented:
does this look like right for the method in the singleton class

static ArrayList<RevDataset> rds = new ArrayList<RevDataset>();
JButton removeButton = new JButton("Remove Dataset");
private static SingletonSelectTable instance = null;

 public JButton getButton() {
         if(rds.size() > 0){
         else {
        return removeButton;

so to use the button in the dialog class woud it be something like

myModel.getButton().addActionListener(new ActionListener() {}  ??
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

jkteaterAuthor Commented:
I have it working thanks to both of you
btw, i'm talking about http:Q_27390851.html#36949991
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.