问题描述
代码
package How;
import java.awt.*;
import javax.swing.*;
public class bin_2 extends JFrame
{
JLabel name=new JLabel(" 用户名");
JLabel key=new JLabel(" 密码");
JTextField t_name=new JTextField();
JPasswordField t_key=new JPasswordField();
JTextArea jTextArea=new JTextArea("我现在不可编辑",10,30);
JScrollPane jScrollPane=new JScrollPane(jTextArea);
public bin_2 ()
{
super("文本组件应用");
this.setLayout(new GridBagLayout());
this.setSize(500, 500);
// this.setResizable(false);
GridBagConstraints gridBagConstraints=new GridBagConstraints();
Container container=this.getContentPane();
myadd(name, container, gridBagConstraints, 0, 0, 1, 1);
myadd(t_name, container, gridBagConstraints, 0, 1, 1, 1);
myadd(key, container, gridBagConstraints, 1, 0, 1, 1);
myadd(t_key, container, gridBagConstraints, 1, 1,1,1);
myadd(jScrollPane, container, gridBagConstraints, 2, 0, 10, 4);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
bin_2 how=new bin_2();
}
public void myadd(Component c, Container con, GridBagConstraints gridBagConstraints,int row, int col, int width,int height)
{
gridBagConstraints.fill=GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor=GridBagConstraints.CENTER;
if(c==jScrollPane)
{
gridBagConstraints.fill=GridBagConstraints.BOTH;
}
gridBagConstraints.gridx=col;
gridBagConstraints.gridy=row;
gridBagConstraints.gridwidth=width;
gridBagConstraints.gridheight=height;
gridBagConstraints.weightx=1;
gridBagConstraints.weighty=1;
con.add(c,gridBagConstraints);
}
}
Java GridBagLayout 无法显示 JScrollPane
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
悬赏问题
- ¥15 机器人轨迹规划相关问题
- ¥15 word样式右侧翻页键消失
- ¥15 springboot+vue 集成keycloak sso到阿里云
- ¥15 win7系统进入桌面过一秒后突然黑屏
- ¥30 backtrader对于期货交易的现金和资产计算的问题
- ¥15 求C# .net4.8小报表工具
- ¥15 安装虚拟机时出现问题
- ¥15 Selenium+docker Chrome不能运行
- ¥15 mac电脑,安装charles后无法正常抓包
- ¥18 visio打开文件一直显示文件未找到