簡體   English   中英

根據JFrame大小調整JPanel寬度

[英]Resize the JPanel width based on the JFrame size

我想知道是否有一種方法可以通過從框架大小中僅調整面板的寬度,而對於高度值,我想保留默認值。

提前致謝!

使用BorderLayout盧克!

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;

public class BorderLayoutExample {

    public static void main(String[] args) {
        JTextArea area = new JTextArea(15, 40);
        JFrame frm = new JFrame("Horizontal resizing");
        // not required, because the default layout here is the BorderLayout.
        // but in common case you probably need to do it.
        frm.setLayout(new BorderLayout());
        // Use BorderLayout.SOUTH - when you want that the top space will not be unused.
        frm.add(new JScrollPane(area), BorderLayout.NORTH);
        frm.pack();
        frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frm.setLocationRelativeTo(null);
        frm.setVisible(true);
    }
}

當您調整框架的大小時,僅文本區域的寬度將被修改。 有關更多信息,請參閱布局管理器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM