Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Java] Removal of JList contents.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sun Feb 28, 2010 1:23 pm    Post subject: [Java] Removal of JList contents. Reply with quote

I'm trying to create a JList which refreshes every 5 seconds but I can't figure out how to remove all of the items so it keeps adding onto the end.

I managed to do it when I was using JList as a variable, but now I'm using it to extend a class (cleaner code Neutral).

Using this:
Code:
TopicListBox topicListBox = new TopicListBox();
JScrollPane listBoxScrollContainer = new JScrollPane(topicListBox);
add(listBoxScrollContainer);


With this:
Code:
public class TopicListBox extends JList {



Here's the JList I'm talking about.


Any ideas? Danke :S
Back to top
View user's profile Send private message MSN Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Feb 28, 2010 8:35 pm    Post subject: Reply with quote

confused as to what you want. Do you just want to delete an item and shift everything up?

Show your code to do it when you used JList as a variable?

_________________
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Mon Mar 01, 2010 2:21 am    Post subject: Reply with quote

well the proper way not sure just googled it.

call

yourJListObject.setListData(new Object[0]);

or create a JList using DefaultListModel

Code:

import.swing.*;
...
DefaultListModel dlm = new DefaultListModel();
yourJListObject = new JList(dlm);


now to add you just use

Code:

dlm.addElement("Post 1 test test");


to delete you can use

Code:

dlm.clear();

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Mon Mar 01, 2010 10:09 am    Post subject: Reply with quote

I'm using a class which extends JList. I've tried to use this.setModel with a DefaultListModel but the clear method does nothing =|
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Mar 01, 2010 4:25 pm    Post subject: Reply with quote

if you post the full source i can try to have a fiddle around with it
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Tue Mar 02, 2010 6:49 am    Post subject: Reply with quote

Make your own clear method using remove and a loop the size of the DLM length

Quote:
public void clear()
Removes all of the elements from this list. The list will be empty after this call returns (unless it throws an exception).


sounds to me like you just want to empty the list.

Code:
public void clear()
{
   for(int i = 0; i < dlm.size(); i++)
       dlm.remove(i);
}

Also incorporate try / catch but i was being lazy


As usual, source makes it easier to debug

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites