Results 1 to 6 of 6
- 05-28-2010, 01:44 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 12
- Rep Power
- 0
Diable JList in JDialog at runtime
Hi,
I am facing a problem with JDialog. I have a JDialog(Modal) which have some panels and controls like- JList, JTextField, JButton etc.
I have two JList one is LstCategory and second is lstSubcategory. If the user select a category and that is valid, lstSubcategory will fill with some options. But if the category is not valid, lstSubcategory will be disabled.
I have used the methods like:
lstSubcategory.setEnabled(false);
or
ScrollSubCategory..setEnabled(false);
But no function is working.
What should be done to disable or enable lstSubcategory at run time?
- 05-28-2010, 02:10 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
How did you do that, through an action listener? Can you show your code here?
- 05-29-2010, 07:16 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 12
- Rep Power
- 0
Hi,
I am doing that in the LstCategory SelectionChaged event. the code part is:
I am unable to find out where the problem is?Java Code:public class SaveDialog { JDialog dlgSave; JList lstCategory,lstSubCategory; DefaultListModel lstModel, lstSubModel; JScrollPane scrollcategory, ScrollSubCategory; //Other controls ........................ SaveDialog() { lstModel = new DefaultListModel( ); lstSubModel = new DefaultListModel( ); dlgSave = new JDialog(); dlgSave.setTitle("Save Parameters"); dlgSave.setModal(true); lstCategory = new JList(lstModel); lstSubCategory = new JList(lstSubModel); lstCategory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); lstCategory.addListSelectionListener(new javax.swing.event.ListSelectionListener(){ public void valueChanged(ListSelectionEvent e) { LstCategorySelectionChanged(e); } } ); scrollcategory = new JScrollPane(lstCategory); scrollcategory.setHorizontalScrollBar(null); scrollcategory.setBounds(3, 200, 180, 45); lstSubCategory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); ScrollSubCategory = new JScrollPane(lstSubCategory); ScrollSubCategory.setHorizontalScrollBar(null); ScrollSubCategory.setBounds(205, 200, 180, 45); // Fill category list with some values ................................... JPanel panel = new JPanel(); panel.setLayout(null); panel.setPreferredSize(new Dimension(400,513)); panel.add(scrollcategory); panel.add(ScrollSubCategory); // other controls and panels .................... dlgSave.add(panel); dlgSave.setResizable(false); dlgSave.setVisible(true); } // close cunstructor // lst category selection changed event // if the user select a valid category, the lstsubcategory will fill up with some values // and enabled otherwise lstsubcategory will be disabled here void LstCategorySelectionChanged(ListSelectionEvent e) { int idx = lstCategory.getSelectedIndex(); if(idx>=0) { if(!lstSubCategory.isEnabled()) lstSubCategory.setEnabled(true); // not working if(lstSubModel.getSize()>0) lstSubModel.clear(); // Check the selected value is valid, fill the subcategory if(valid) { // fill the subcategory .......................... } else { lstSubCategory.setEnabled(false); // not working } } } // closing selection event } // closing of the classLast edited by Eranga; 05-31-2010 at 03:45 AM. Reason: code tags added
- 05-29-2010, 08:08 AM #4
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
> What should be done to disable or enable lstSubcategory at run time?
worked OK for me
- 05-29-2010, 11:58 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 12
- Rep Power
- 0
I have find out where the problem was. Thanks to all.
- 05-31-2010, 03:48 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nice to hear that you've solve the problem. And also if someone else comes with the quite similar issue, your comment may be really helpful. So why don't you send the solution here as well.
And also please use code tags when you posting code segments in the forum. Unformated codes are really hard to read. If you don't know how to do it, please look at the my forum signature. You can find the related link.
Similar Threads
-
JDialog
By frenk_castle in forum AWT / SwingReplies: 3Last Post: 05-11-2010, 12:28 PM -
Close JDialog
By sky in forum AWT / SwingReplies: 7Last Post: 11-16-2009, 06:01 PM -
JDialog appearing in the toolbar
By riddick in forum New To JavaReplies: 6Last Post: 11-06-2009, 02:19 PM -
setLocation on a JDialog is ignored
By ScottVal in forum AWT / SwingReplies: 7Last Post: 01-13-2009, 07:35 AM -
help with jdialog
By leonard in forum AWT / SwingReplies: 1Last Post: 08-05-2007, 05:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks