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


Button Logic

Posted on 2011-10-20
Medium Priority
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.

      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?
Question by:jkteater
  • 3
  • 2
LVL 86

Accepted Solution

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
LVL 47

Assisted Solution

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

Author Comment

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){
         else {
        return removeButton;

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

myModel.getButton().addActionListener(new ActionListener() {}  ??
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

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

Expert Comment

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

Expert Comment

ID: 37000825

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