Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-17-2012, 10:20 AM   PM User | #1
jordandap
New Coder

 
Join Date: Jul 2011
Posts: 44
Thanks: 5
Thanked 0 Times in 0 Posts
jordandap is an unknown quantity at this point
repopulating JLists?

Hello I am making a program that auto clears and then repopulates a JList depending on what you have done.

I have managed to clear all the entries in the JList but can't seem to add any
Code:
private static ConstantsS[] = {};
private static VariablesS[] = {};
private void VarConUpdate()
	{
		ConstantsList.removeAll();
		VariablesList.removeAll();
                //what i want to do is put all of the VariableS[] in VariablesList
                //and all ConstantsS[] ConstantsList
                //how would I achieve this?
	}
public GUIOutput()
{
               JScrollPane ScrollPaneConstants = new JScrollPane();
		ScrollPaneConstants.setBounds(636, 30, 126, 320);
		getContentPane().add(ScrollPaneConstants);

		ConstantsList = new JList();
		ScrollPaneConstants.setViewportView(ConstantsList);
		ConstantsList.setVisibleRowCount(5);
}
jordandap is offline   Reply With Quote
Old 08-17-2012, 08:31 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Code:
foreach(String s in VariableS)
{
  VariablesList.Add(s);
}
Should be something very close to that... could also do a for loop...
Code:
for(int i = 0; i < VariableS.Length; i++)
{
  VariablesList.Add(VariableS[i]);
}
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 08-18-2012, 09:12 PM   PM User | #3
jordandap
New Coder

 
Join Date: Jul 2011
Posts: 44
Thanks: 5
Thanked 0 Times in 0 Posts
jordandap is an unknown quantity at this point
thanks what i did in the first place worked but it was due to another problem in my program not my loop.
jordandap is offline   Reply With Quote
Old 08-19-2012, 05:15 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Its not quite as easy in Java as it is in C# to add to a jlist. If you want to actually add an item to a JList, you need to add it to the list's model. That's a simple matter of retrieving the list model, and casting it:
PHP Code:
((DefaultListModel)mylist.getModel()).addElement(anObject); 
Should do it.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:10 AM.


Advertisement
Log in to turn off these ads.