2

これが私のコードです:

//this is a JPanel, the gray panel behind the A4 paper
public Panel(int w, int h) {  //w=624, h=600
    this.w = w;
    this.h = h;
    ownlayout();
    setLocation(0, 0);
    setSize(w,h);
    setBackground(Color.gray);

    JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL);
    vbar.setLocation(w-30,0);
    Tab tab = new Tab(w-30,842);
    //Tab is a JPanel too, this is the A4 paper
    add(tab);
    add(vbar);
}
private void ownlayout() {
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    /*layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, w, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, h, Short.MAX_VALUE)
    );*/
}

タブ パネルの高さが灰色のパネルの高さよりも大きいことがわかります。だから私は、灰色のパネルの右側にスクロールバーを取得して、タブパネル(灰色のパネルにあります)を上下にスクロールできるようにしたいと考えています。しかし、それはタブパネルを表示するだけで、スクロールバーはありません! ownlayout() ではなくレイアウト ボーダーを設定すれば、これを行うことができますが、borderlayout ではなく自由なデザインが必要です。いくつかの例で私を助けてください!

4

1 に答える 1

6
JScrollPane thePane = new JScrollPane(yourBigComponent);
container.add(thePane);
于 2011-03-10T21:19:01.157 に答える