문제

I have two simple JPanels, one positioned on top and the other on the bottom.

Now im trying to resize the top panel to take up more space (and therefore push the bottom panel down)

Ive added a button where i listen on call like:

  button.addMouseListener(new MouseAdapter() {  
      public void mouseReleased(MouseEvent e) {   
          panelTop.setSize(10, 200);
      }  
  });

This is how i add my panels:

add(panelTop, BorderLayout.NORTH);
add(panelBottom, BorderLayout.SOUTH);

Any ideas if this is possible?

My tests are not working at all

도움이 되었습니까?

해결책 2

You should use setPreferredSize instead of setSize. The BorderLayout will notice this and resize the panel on the next validate().

다른 팁

What you are trying to do can be easily solved with a JSplitPane

This will take two components and put a divider between the two that you can use to re-size them.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top