2016-06-06 5 views
0

나는 3 개의 패널을 가진 어플리케이션을 만들었습니다. 상태, btn 및 상단 패널. 일부 단추는 btn 패널에 추가되고 일부 레이블은 상태 패널에 있고 일부 텍스트 필드는 상단 패널에 추가되었습니다. 이 모든 패널은 JFrame에 추가됩니다. 이 모든 것을 JScroller에 넣고 싶었습니다. 나는이 일을하는 방법에 대해 확신하지 못한다. 나는 모든 것을 놓은 방법을 보여주는 코드를 추가했다.JScroll에 패널 추가하기

static FlowLayout topPanelLayout = new FlowLayout(); 
static GridLayout parentLayout = new GridLayout(0,1); 
static GridLayout statusLayout = new GridLayout(2,1); 
static JFrame frame = new JFrame("Web API Interface"); 
static JPanel statusPanel; 
static JPanel btnPanel; 
static JPanel topPanel;  frame.setLayout(parentLayout); 

    // -- Create Panels 
    topPanel = new JPanel(topPanelLayout); 
    statusPanel = new JPanel(statusLayout); 
    btnPanel = new JPanel(new GridLayout(0,2)); 

    frame.setSize(1100,600); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); statusPanel.add(statusLabel); 
    statusPanel.add(connectionStatusLabel); 
    statusPanel.add(cidLabel); 

    // -- add label and textfield at the top panel which is at the top of 
    // the frame 
    topPanel.add(new JLabel("Enter IP:")); 
    topPanel.add(ipAddressField); 



    // -- 1.) add top panel .... everything goes in order down 
    frame.getContentPane().add(topPanel); 
    frame.getContentPane().add(statusPanel); 
    frame.getContentPane().add(btnPanel); 
    //Display the window. 
    frame.setVisible(true); 

답변

0

JScroller

JScroller 란 ??? 적절한 클래스 이름을 사용하여 우리가 정확히 무엇을 말하고 있는지 알 수 있습니다.

프레임에 3 개의 패널을 추가하지 마십시오.

대신 3 개의 패널을 다른 패널에 추가하십시오. 그럼 당신은 그 패널을 사용하여 JScrollPane를 작성하고 마지막으로 당신은 프레임에 스크롤 창을 추가

//frame.getContentPane().add(topPanel); 
//frame.getContentPane().add(statusPanel); 
//frame.getContentPane().add(btnPanel); 
JPanel parent = new JPanel(parentLayout); 
parent.add(topPanel); 
parent.add(statusPanel); 
parent.add(btnPanel); 
frame.add(new JScrollPane(parent)); 

을 또한, 모든 정적 변수를 제거. 코드가 올바르게 설계된 경우 변수가 정적 일 필요가 없습니다.