I have a list of JXHyperlinks, I need to retrieve them one by one and add to a panel
the code is:
for(int i=1; i<=lcol-1;i++)
{
a2=sheet.getCell(i,0);
stringy=a2.getContents();
testlink= new JXHyperlink(new Action(stringy));
list.add(testlink);
}
for(int i=0;i<list.getModel().getSize();i++)
{
panel2.add(list.getModel().getElementAt(i));
}
the first loop is creating the list of links with their respective names (taken from an excel file). The second loop takes the pre-made list and adds each object to a panel. The problem is that id doesn't add them.
The problem is, you are adding the
JXHyperlink
components directly to the list, not the list model.This is not how lists should work.
Instead, add the link
String
to theListModel
and use theJXHyperlink
as a bases for aListCellRenderer
, then add an instance ofJXHyperlink
to the panel for eachString
in the listSee How to use lists for more details, in particular, Creating a model and Writing a Custom cell Renderer