Actualize a JScrollPane

Hi everyone in the forum,

i am developing a screen with a JScrollPane, which contains some line of text formatted as radioButtons. The point is that when i am trying to actualize the contain of the ScrollPane, nothing happens, i mean, i can see no change, i am doing sometrhing wrong, any idea? The function actualize is called when a button in the app is clicked, meanwhile the collisionConfiguration is called just the first time when the window is created

Many Thanks

privatestatic JComponent collisionConfiguration(String[] collision,int selected){

JPanel collisionPanel=new JPanel(new BorderLayout());

//box which will content the isotopes as checkboxes

Box box = Box.createVerticalBox();

JScrollPane pScroll =new JScrollPane(box, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,

JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

actualizeCollisions(collision, selected);

collisionPanel.add(scrollPaneForListBox, BorderLayout.CENTER);

collisionPanel.setBorder(BorderFactory.createTitledBorder("Parameters"));

return collisionPanel;

}

privatestaticvoid actualizeCollisions(String[] collision,int selected){

if (scrollPaneForListBox !=null){

scrollPaneForListBox.removeAll();

}

collision= configColisiones(collision);

if (collision.length != 0){

final JList listCollisions =new JList( createDataCollisions(collision) );

listCollisions.setCellRenderer(new RadioListRender());

listCollisions.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

listCollisions.setBorder(new EmptyBorder(0,4,0,0));

CheckableItem item = (CheckableItem)listCollisions.getModel().getElementAt(selected -1);

item.setSelected(true);

listCollisions.addMouseListener(new MouseAdapter(){

publicvoid mouseClicked(MouseEvent e){

final String collision_selected;

int index = listCollisions.locationToIndex(e.getPoint());

CheckableItem item;

//deselect all the radio buttons

for (int i=0;i<listCollisions.getModel().getSize();i++){

item = (CheckableItem)listCollisions.getModel().getElementAt(i);

item.setSelected(false);

}

listCollisions.repaint();

//select the one we are interested in

item =(CheckableItem)listCollisions.getModel().getElementAt(index);

item.setSelected(! item.isSelected());

collision_selected = String.valueOf(index);

Rectangle rect = listCollisions.getCellBounds(index, index);

listCollisions.repaint(rect);

}

});

//Add the scrollbar in case there were too many isotopes

scrollPaneForListBox.add(listCollisions);

scrollPaneForListBox.repaint();

}

}

>

[4171 byte] By [patucosa] at [2007-10-3 4:11:45]
# 1

You don't seem to be adding anything to 'box.'

You also seem to be using two scroll anes, 'pScroll' and 'scrollPaneForListBox.'

You also seem to be adding 'listCollisions' directly to a scroll pane when you should probably be using 'setView()'

Your code's a bit hard to follow to be honest, but some or all of the above may be causing your problems. You'd be best off writing a small compilable example if you need further help.

And, "actualize" ....? I guess it means something to you :o)

itchyscratchya at 2007-7-14 22:12:24 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks for the reply.

Apologize myselft for the bad code i am implementing, but it something related with stress and running out of time, i am concious it is not the best way, but i have to follow it, just for a time (as short as possible )

I have reviewed the code following your comments and about the box and the JScroll u are right and they are not neccesary at first sight. The point is i am trying to have CheckBoxes in a Panel created dynamically depending the number of collisions i have for each configuration, so i created the actualize function, to call it although with events. But instead of seeing anything, the scroll pane is totally empty.

I do not know what is seView about the list of CheckableItem.

Thanks for your time and help

patucosa at 2007-7-14 22:12:24 > top of Java-index,Desktop,Core GUI APIs...
# 3
and sorry for my English. :)instead of apologize myself -> apologize meAnd about the collision is something related with mollecules and collision with another ones, following some algorithms. SOmething which is making me crazy :)
patucosa at 2007-7-14 22:12:24 > top of Java-index,Desktop,Core GUI APIs...
# 4

instead of apologize myself -> apologize me

I think you mean either "I apologize" or "forgive me," but anyway, no apologies are necessary :o)

I do not know what is seView about the list of CheckableItem.

JScrollPane has a JViewport which is accessible via the getViewport() method - this has a setView() method (JScrollPane also has the convenience setViewportView() method). It is this method that you should use to set the 'content' of the scroll pane, not the add() method.

itchyscratchya at 2007-7-14 22:12:24 > top of Java-index,Desktop,Core GUI APIs...
# 5

Thanks for the reply,

i gonna check it right now and i will post how it goes in a couple minutes.

And i should apologize because you are "wasting" your time helping me, and more than a lot.

I realize i should keep an (huge) eye when i post the code, cuz sometimes i am not doing as much as i am supposed to make things easier due to the stress.

Thanks again :)

patucosa at 2007-7-14 22:12:24 > top of Java-index,Desktop,Core GUI APIs...
# 6
Hi again,i have tryed directly the setViewPort method, and it is working!!! many many thanks. Just doing:scrollPaneForListBox.setViewportView(listCollisions);Appart from that the first thing i was doing (remove all elements in the pane ) was uncorrect too.
patucosa at 2007-7-14 22:12:24 > top of Java-index,Desktop,Core GUI APIs...