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.

 removeButton.setEnabled(false);
      if(checkList > 0){
            removeButton.setEnabled(true);
 }

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?
jkteaterAsked:
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.

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

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
for_yanCommented:
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
0
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){
               removeButton.setVisible(true);    
         }
         else {
               removeButton.setVisible(false);
         }
        return removeButton;
   }

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

myModel.getButton().addActionListener(new ActionListener() {}  ??
0
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
0
CEHJCommented:
btw, i'm talking about http:Q_27390851.html#36949991
0
CEHJCommented:
:)
0
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
Java

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.