JPanlPane이 내 구성 요소 위에 앉아 있지 않도록 JPanel에 공백을 추가하려면 어떻게해야합니까?

StackOverflow https://stackoverflow.com/questions/6059155

문제

JScrollPane이 있고 내 응용 프로그램을로드 할 때 막대가 내 버튼 중 하나 위에 앉아 있습니다.내가하고 싶은 일은 스크롤 막대가 내 버튼이 아닌 공간을 그립니다.

시도한 예제 코드 :

JPanel eButton = new JPanel(new BorderLayout());
JPanel spaceFiller = new JPanel();
spaceFiller.setSize(30, 10);
eButton.add(editButton, BorderLayout.EAST);
eButton.add(spaceFiller, BorderLayout.WEST);
.

이 코드의 문제점은 여전히 내 버튼을 덮어 쓰고 공간이 추가되지 않는다는 것입니다.JScrollPane이 내 JFrame에 구성 요소와 겹치지 않는지 확인하는 가장 좋은 방법은 무엇입니까?

감사합니다

도움이 되었습니까?

해결책

To ensure that the size of the JPanel is respected you should use setPreferredSize() instead of setSize().

다른 팁

In your sample code, didn't you reverse EAST and WEST? Shouldn't it be like:

eButton.add(editButton, BorderLayout.WEST); 
eButton.add(spaceFiller, BorderLayout.EAST); 

That would make more sense, sicne the scrollbar will appear on the right side (EAST).

Please note that the solution you suggest, even though it may work (after exchanging EAST and WEST) looks more like a hack than a real solution.

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