展开全部
给的分有点少了,看看效果还满意吗?如果满意加分啊!O(∩_∩)O哈哈~
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class TextFile extends JFrame {
private Container c;
private JTextField jtf;//文本框
private JButton jb;//按钮
private JComboBox jc;//下拉框
private JTextArea jta;//文本区
private JScrollPane jsp;
public TextFile() {
this.setTitle("页面展示");
c = this.getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
this.setLayout(gridbag);
jtf = new JTextField();
jb = new JButton("BUTTON开始");
String[] city = {"下拉框列表", "中国", "美国", "英国"};
jc = new JComboBox(city);
jta = new JTextArea();
jta.setRows(10);//设置文本区列数
jsp = new JScrollPane();
gbc.anchor = GridBagConstraints.NORTH; // 当组件没有空间大时,使组件处在北部
gbc.fill = GridBagConstraints.HORIZONTAL;;
gbc.gridx = 0;//横坐标
gbc.gridy = 0;//纵坐标
gbc.gridwidth = 2;//横占几个网格
jtf.setText("这里是文本框,显示一些东西");
gridbag.setConstraints(jtf, gbc);
c.add(jtf);
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(10, 0, 0, 10); // 组件彼此的间距
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.ipadx = 0; // 组件内部填充空间,即给组件的最小宽度添加多大的空间
gbc.ipady = -100; // 组件内部填充空间,即给组件的最小高度添加多大的空间
gridbag.setConstraints(jc, gbc);
c.add(jc);
gbc.insets = new Insets(10, 0, 10, 0); // 组件彼此的间距
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.ipadx = 0; // 组件内部填充空间,即给组件的最小宽度添加多大的空间
gbc.ipady = 0; // 组件内部填充空间,即给组件的最小高度添加多大的空间
gridbag.setConstraints(jb, gbc);
c.add(jb);
jta.setText("这里输出内容,可以往下拉");
gbc.insets = new Insets(10, 0, 0, 0); // 组件彼此的间距
gbc.gridx = 0;
gbc.gridy = 3;
gbc.gridwidth = GridBagConstraints.REMAINDER;
jsp.setViewportView(jta);
gridbag.setConstraints(jsp, gbc);
c.add(jsp);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
new TextFile();
}
}
有什么其他要问的,你可以百度hi我!
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class TextFile extends JFrame {
private Container c;
private JTextField jtf;//文本框
private JButton jb;//按钮
private JComboBox jc;//下拉框
private JTextArea jta;//文本区
private JScrollPane jsp;
public TextFile() {
this.setTitle("页面展示");
c = this.getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
this.setLayout(gridbag);
jtf = new JTextField();
jb = new JButton("BUTTON开始");
String[] city = {"下拉框列表", "中国", "美国", "英国"};
jc = new JComboBox(city);
jta = new JTextArea();
jta.setRows(10);//设置文本区列数
jsp = new JScrollPane();
gbc.anchor = GridBagConstraints.NORTH; // 当组件没有空间大时,使组件处在北部
gbc.fill = GridBagConstraints.HORIZONTAL;;
gbc.gridx = 0;//横坐标
gbc.gridy = 0;//纵坐标
gbc.gridwidth = 2;//横占几个网格
jtf.setText("这里是文本框,显示一些东西");
gridbag.setConstraints(jtf, gbc);
c.add(jtf);
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(10, 0, 0, 10); // 组件彼此的间距
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.ipadx = 0; // 组件内部填充空间,即给组件的最小宽度添加多大的空间
gbc.ipady = -100; // 组件内部填充空间,即给组件的最小高度添加多大的空间
gridbag.setConstraints(jc, gbc);
c.add(jc);
gbc.insets = new Insets(10, 0, 10, 0); // 组件彼此的间距
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.ipadx = 0; // 组件内部填充空间,即给组件的最小宽度添加多大的空间
gbc.ipady = 0; // 组件内部填充空间,即给组件的最小高度添加多大的空间
gridbag.setConstraints(jb, gbc);
c.add(jb);
jta.setText("这里输出内容,可以往下拉");
gbc.insets = new Insets(10, 0, 0, 0); // 组件彼此的间距
gbc.gridx = 0;
gbc.gridy = 3;
gbc.gridwidth = GridBagConstraints.REMAINDER;
jsp.setViewportView(jta);
gridbag.setConstraints(jsp, gbc);
c.add(jsp);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
new TextFile();
}
}
有什么其他要问的,你可以百度hi我!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询