jscrollpane에서 레이아웃 관리자없이 고정 크기의 jpanel을 갖고 싶습니다 (레이아웃 관리자도 없음). 나는 사용자가 클릭 (그리고 생성 된 모든 emelents 위해 드래그 & 드롭을 허용) 위치에서 사각형/원을 만들 필요가 있기 때문에 나는자바 스윙, 스크롤바가 절대 레이아웃과 함께 작동하지 않습니다.
setLocationRelativeTo(null);
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setName("dnd test");
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane scroll = new JScrollPane(panel,v,h);
scroll.setLayout(null);
scroll.setPreferredSize(new Dimension(1000, 1000));
scroll.setBounds(0, 0, 1000, 1000);
panel = buildComponentOnAbsoluteLayout(new JPanel(),scroll,0,0,500,500);
panel.setBackground(Color.darkGray);
panel.setSize(350,350);
panel.setLayout(null);
buildComponentOnAbsoluteLayout(new JButton("button 1"),panel,10,10,120,30);
buildComponentOnAbsoluteLayout(new JButton("button 1"),panel,50,50,120,30);
add(scroll);
setVisible(true);
public static <T extends JComponent> T buildComponentOnAbsoluteLayout(T t,Container holder,int x, int y,int width, int heigth){
t.setBounds(x,y,width,heigth);
holder.add(t);
return t;
}
스크롤 막대가 나타하지 않습니다 어떤 레이아웃 매니저를 사용하지 못할.
Java GUI는 다른 OS, 화면 크기, 화면 해상도 등에서 작동해야합니다. 따라서 픽셀 완벽한 레이아웃에 도움이되지 않습니다. 대신 레이아웃 관리자 또는 [조합] (http://stackoverflow.com/a/5630271/418556)과 [공백] 레이아웃 채우기 및 테두리 (http://stackoverflow.com/a/17874718/)를 사용하십시오. 418556). –
레이아웃 관리자를 사용할 수 없습니다. 메신저, 일부 사용자는 작업 공간 (jpanel)에서 객체를 생성하고 다른 객체에 객체를 연결할 수 있습니다. – hnnn
이것은 문제가되지 않습니다. 드래그 앤 드롭을 구현하고 사용하려는 레이아웃 관리자에 구성 요소를 동적으로 추가하십시오. null 레이아웃을 사용하면 아마도 * 작동하지 않을 것입니다. 셰이프를 그리려면 레이아웃과 관련이없는 그래픽 개체를 사용하십시오. – user1803551