1

If I add a new component, the scrollpane does not up update. Can I update it without creating a new JScrollPane?

 public void start(){
        getBox_Topics().setBorder(new TitledBorder(new EtchedBorder(),"Topics of vote"));
        add(new JScrollPane(getBox_Topics(),
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
        pack();
        setHandler(new ClientHandler_Thread(this));
        getHandler().start();
        setVisible(true);
    }

Buttons add the new component in Box:

enter image description here

Cardinal System
  • 2,749
  • 3
  • 21
  • 42

1 Answers1

0

The Box/JPanel must is fixed size. Or it must have MaximumSize.

public void start(){
    getBox_Topics().setBorder(new TitledBorder(new EtchedBorder(),"Topics of vote"));
    setScrollPane(new JScrollPane(getBox_Topics()));
    add(getScrollPane());
    getScrollPane().setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    getBox_Topics().addContainerListener(new ContainerListener() {
        @Override
        public void componentAdded(ContainerEvent containerEvent) {
            getScrollPane().revalidate();
            getScrollPane().repaint();
        }

        @Override
        public void componentRemoved(ContainerEvent containerEvent) {

        }
    });
    pack();
    setHandler(new ClientHandler_Thread(this));
    getHandler().start();
    setVisible(true);
}