일부 GUI 객체 중첩 작업을하고 있습니다. 나는 그것의 대부분을 지금까지 작동시키지 만, 내가 알 수없는 가장 최근의 부분을 얻었습니다. 그것은 간단한 문제일지도 모르고 중첩의 깊이가 문제를 일으키는 것은 아니라고 생각합니다. 그렇지만 내가 가지고있는 것을 열거 할 것입니다.JSplitPane 내의 JScrollPane에 JPanel 추가
지금까지 내가 가지고 JFrame
포함하는 JTabbedPane
이있는 JPanel
, 그것은이 JTabbedPane
이있다 2 JPanels
. 현재 JPanels
중 하나를 작업하고 있습니다. 및 JSplitPane
을 포함하는 JSplitPane
이 포함되어 있습니다. 두 번째 JSplitPane
에는 두 개의 JScrollPane
이 있습니다. JScrollPane
중 하나는 JPanel
입니다.
이것은 모두 마지막으로 JPanel
까지 올바르게 작동합니다. 제대로 작동하는지 테스트하기 위해 배경을 추가했습니다. 내 문제는 배경이 기본적으로 JScrollPane
내의 테두리로 표시된다는 것입니다. 배경이없는 것처럼 패널의 내부는 회색입니다.
여기 내 코드 중 일부입니다. 누군가가 유용하다고 생각한다면 더 많은 것을 제공 할 수 있습니다.
이것은 JTabbedPane
내에있는 JPanel
입니다.
public class MapEditor extends JPanel{
int height, width;
final int DIVIDER_SIZE = 7;
final int HORIZONTAL_DIVIDER_PLACE = 300;
final int VERTICAL_DIVIDER_PLACE = 200;
//side bar divider separates main page and left (vertical divider)
//side bar division separates top and bottom of sidebar (horizontal divider)
JSplitPane sideBarDivider;
JSplitPane sideBar;
//scroll pane to hold tiles panel, map panel
JScrollPane toolContainer;
JScrollPane tileContainer;
JScrollPane mapContainer;
//panels held inside JScrollPanes above
JPanel toolPanel;
JPanel tilePanel;
JPanel mapPanel;
public MapEditor(int w, int h){
this.width = w;
this.height = h;
setLayout(new BorderLayout());
//we can just pass the final variables in here because it's in the top left
toolPanel = new ToolPanel(HORIZONTAL_DIVIDER_PLACE,
VERTICAL_DIVIDER_PLACE);
sideBar = splitScreen();
add(sideBar);
}
//main split between map and tools/tiles
public JSplitPane splitScreen(){
mapContainer = new JScrollPane();
sideBar = buildSideBar();
//add map container and sidebar
sideBarDivider = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
sideBar, mapContainer);
sideBarDivider.setSize(width, height);
//set divider size and position
sideBarDivider.setDividerLocation(HORIZONTAL_DIVIDER_PLACE);
sideBarDivider.setDividerSize(DIVIDER_SIZE);
return sideBarDivider;
}
//small split between tools and tiles
public JSplitPane buildSideBar(){
toolContainer = new JScrollPane();
toolContainer.add(toolPanel);
tileContainer = new JScrollPane();
//add tile & tool containers
sideBar = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
toolContainer, tileContainer);
//set divider size and position
sideBar.setDividerSize(DIVIDER_SIZE);
sideBar.setDividerLocation(VERTICAL_DIVIDER_PLACE);
return sideBar;
}
}
이것은 제게 문제가되는 패널입니다.
public class ToolPanel extends JPanel{
int width, height;
public ToolPanel(int w, int h){
this.width = w;
this.height = h;
setLayout(new BorderLayout());
setSize(w, h);
setBackground(Color.BLACK);
}
}
아무도 내가 잘못 아무것도 볼? 필자는 Java GUI 구성 요소에 익숙하지 않으며 누구 에게든 도움을 주어야 할 것입니다.
문제를 해결해 주셔서 감사합니다. –