473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

help, having trouble with en/dis-abling button

Hi, I am currently making a list, where users can click the Add-button to add stuffs to the list, and click the Delete-button to delete the selected item.

However, because it starts with an Empty list, I want the Delete-button to disable at first. (see the third line with "<<< check").. then it will enable as long as there is one item in the list. but if the user deletes all the items, it will go back to disable form.

But somehow, it is not enabling even I put the deletestateButton.setEnabled(true);

can someone help?
Expand|Select|Wrap|Line Numbers
  1. //create the deletestate button
  2. deletestateButton = new JButton("Delete State");
  3. deletestateButton.setEnabled(false); // <<<<<<<<<<<< check
  4.  
  5. deletestateButton.addActionListener(new ActionListener(){
  6.     public void actionPerformed(ActionEvent e) {
  7.         int index = statelist.getSelectedIndex();
  8.         int size = listModel.getSize();
  9.         listModel.remove(index);
  10.         if (size == 0) {
  11.             deletestateButton.setEnabled(false);
  12.         } else {
  13.             deletestateButton.setEnabled(true); <<<<< HERE
  14.             if (index == size) {
  15.                 //removed item in last position
  16.                 index--;
  17.             }
  18.             statelist.setSelectedIndex(index);
  19.             statelist.ensureIndexIsVisible(index);
  20.         }
  21.         //face.setAwake(false);
  22.     }//end listener
  23. });
Jan 20 '08 #1
2 1121
sukatoa
539 512MB
If i were you, i just set the button's visibility state into false...
or Set the button's focusable state... It looks like disabled...

So nobody can click it, focus on it, or etc....
Jan 20 '08 #2
BigDaddyLH
1,216 Expert 1GB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Jan 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ron Adam | last post by:
Can anyone show me an example of of using dis() with a traceback? Examples of using disassemble_string() and distb() separately if possible would be nice also. I'm experimenting with...
19
by: pkilambi | last post by:
I wrote this function which does the following: after readling lines from file.It splits and finds the word occurences through a hash table...for some reason this is quite slow..can some one...
15
by: carr4895 | last post by:
Hello. I was wondering if someone could help me too with a login form. Upon startup, I have to display a password screen and it should accept a user name and password. User name can be anything...
4
by: ramapv | last post by:
Hi ! I am working on linux platform. I have some problem with sockets.I want to communicate with a C machine through sockets. I find few problems in it. The way i am creating socket in my jsp...
2
by: angelcd | last post by:
hi guys, i have here my sample program, actually it compiles and run but some of the output does'nt come out on the screen.. can someone help me what's wrong with this... here's my code: ...
1
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket)....
3
by: MohanaAngamuthu | last post by:
When i compile the below program i get the error as: filereading.java:21: warning: readLine() in java.io.DataInputStream has been deprecated while( (record=dis.readLine()) != null ) ...
14
by: EJ | last post by:
I'm real new to javasscript. The task is to develop a web page which will allow users to customize a laptop ... show the price as they change options ... transfer the price and system description...
4
by: uidzer0 | last post by:
Hey everyone, I'm having a little trouble writing an algorithm to create a hierarchal structure from a database which looks like this: Code: parent_id | child_id |...
0
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.