Java 根据JFrame大小调整JPanel宽度
我想知道是否有一种方法可以通过从框架大小调整面板的宽度,而对于高度值,我想保留默认值Java 根据JFrame大小调整JPanel宽度,java,swing,jframe,jpanel,layout-manager,Java,Swing,Jframe,Jpanel,Layout Manager,我想知道是否有一种方法可以通过从框架大小调整面板的宽度,而对于高度值,我想保留默认值 提前谢谢 使用BorderLayoutLuke import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class BorderLayoutE
提前谢谢 使用
BorderLayout
Luke
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);
}
}
调整框架大小时,仅修改文本区域的宽度。有关更多信息,请阅读使用
BorderLayout
Luke
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);
}
}
调整框架大小时,仅修改文本区域的宽度。有关更多信息,请阅读