Skip to main content

Jxta and GUI

5 replies [Last post]
dc5
Offline
Joined: 2008-08-31

Hey,

I am currently designing the GUI for my JXTA application and have been trying to think of someways to represent the advertisments discovered to the user in some sort of list, probably a JList.

Just wondering if any of you have done such a thing or done it in a different way?

Intersting to know others idea's

Cheers,

DC5

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jtanago
Offline
Joined: 2008-06-18

What kind of list? A list with the name of the adv or with the whole adv?

dc5
Offline
Joined: 2008-08-31

Hey,

Just a list of names, not the whole advertisement but the names in the list would need to link to there full advertisement. So when a name is selected in the list the advertisement linked to thath name can be retreived and used.

Cheers,

DC5

jtanago
Offline
Joined: 2008-06-18

Ok,

//Declare a linkedlist to store the advertisements
[i]LinkedList groupLinkedList = new LinkedList();[/i]
// A list with an associated model. To modify the list we must modify the model.
[i]JList groupList ;
DefaultListModel model = new DefaultListModel();
groupList.setModel(model);[/i]

// Get the discoveryservice
[i]DiscoveryService discovery = NetPeerGroup.getDiscoveryService();[/i]
// Get the local advertisements
[i]Enumeration advEnum = discovery.getLocalAdvertisements(DiscoveryService.GROUP, null, null);
if (advEnum != null) {[/i]
// Add each advertisement to the linked list.
[i] while (advEnum.hasMoreElements()) {
groupLinkedList.add((PeerGroupAdvertisement) listaADV.nextElement());
}
}[/i]

// Add each linkedlist element to the jList. As you can see, we only add the name of the advertisement.
[i]try {
for (int i = 0; i < groupLinkedList.size(); i++) {
model.addElement(groupLinkedList.get(i).getName());
}
} catch (IOException ex) {

}[/i]

At this point you have a linked list and a list with elements correlated. Element i in JList represent the advertisement i in the linked list. You can get the i element with this code
[i]int groupIndexSelected = groupList.getSelectedIndex();[/i]

Message was edited by: jtanago

At this point you have a linked list and a list with elements correlated. Element i in JList represent the advertisement i in the linked list. You can get the i element with this code
[i]int groupIndexSelected = groupList.getSelectedIndex();[/i]

Message was edited by: jtanago

jtanago
Offline
Joined: 2008-06-18

At this point you have a linked list and a list with elements correlated. Element i in JList represent the advertisement i in the linked list. You can get the i element with this code
[i]int groupIndexSelected = groupList.getSelectedIndex();[/i]

dc5
Offline
Joined: 2008-08-31

jtanago thats exactly what I am looking to do!

Thank you for your help, much appreciated.

Cheers,

DC5