[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Button Logic

Posted on 2011-10-20
6
Medium Priority
?
249 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:jkteater
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
ID: 37000249
In the same routine that fires TableModel events, check the state of your underlying Collection and en/disable the button accordingly
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 300 total points
ID: 37000301
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
 

Author Comment

by:jkteater
ID: 37000722
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jkteater
ID: 37000797
I have it working thanks to both of you
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37000811
btw, i'm talking about http:Q_27390851.html#36949991
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37000825
:)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question