javapanel根据内部组件_Java GUI:将JPanel添加进JScrollPane

public static voidqanda(){final JFrame frame=menu(newJFrame());

user.setNickname("zs");

user.setRole(1);

List questions=qandaDao.getQuestions();

JButton jButton_ask=new JButton("Ask Question");

frame.add(jButton_ask);

jButton_ask.setBounds(440, 200, 120, 30);

jButton_ask.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent e) {//TODO Auto-generated method stub

}

});

JPanel jPanel_qanda=newJPanel();

jPanel_qanda.setPreferredSize(new Dimension(800,150*questions.size()));

jPanel_qanda.setLayout(null);for (int i = 0; i < questions.size(); i++) {

String name=questions.get(i).getName();

String time=questions.get(i).getTime();

String content=questions.get(i).getContent();

JLabel jLabel_name=new JLabel("Name:"+name);

jPanel_qanda.add(jLabel_name);

jLabel_name.setBounds(20, 20+150*i, 60, 20);

JLabel jLabel_time=new JLabel("Time:"+time);

jPanel_qanda.add(jLabel_time);

jLabel_time.setBounds(220, 20+150*i, 160, 20);

JButton jButton_answer=new JButton("Answer");

jPanel_qanda.add(jButton_answer);

jButton_answer.setBounds(420, 20+150*i, 120, 30);

jButton_answer.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent e) {//TODO Auto-generated method stub

}

});

JButton jButton_check=new JButton("Check");

jPanel_qanda.add(jButton_check);

jButton_check.setBounds(620, 20+150*i, 120, 30);

jButton_check.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent e) {//TODO Auto-generated method stub

}

});

JTextArea jTextArea_content=newJTextArea(content);

jPanel_qanda.add(jTextArea_content);

jTextArea_content.setBounds(20, 50+150*i, 740, 80);

}

JScrollPane jScrollPane_userInfo=newJScrollPane(jPanel_qanda,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

frame.add(jScrollPane_userInfo);

jScrollPane_userInfo.setBounds(100, 250, 800, 200);

jScrollPane_userInfo.setFont(new Font("Dialog", 0, 20));

}/*** 用户信息*/

public static voiduserInfo(){

JFrame frame=newJFrame();

user.setNickname("zs");

frame.setSize(1000,600);

frame.setVisible(true);

frame.setResizable(false);

frame.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width-400)/2,

(Toolkit.getDefaultToolkit().getScreenSize().height-320)/2);

frame.setTitle("Notice");

frame.setLayout(null);

frame=menu(frame);

List users=userDao.getUsers();

String[][] userInfos=new String[users.size()][4];for(int i=0;i

userInfos[i][0]=users.get(i).getNickname();

userInfos[i][1]=users.get(i).getAccount();

userInfos[i][2]=users.get(i).getEmail();if(users.get(i).getRole()==0){

userInfos[i][3]="Student";

}else{

userInfos[i][3]="Teacher";

}

}

String[] header=new String[]{"Name","Account","Email","Role"};

JTable jTable_userInfo=newJTable(userInfos,header);

JScrollPane jScrollPane_userInfo=newJScrollPane(jTable_userInfo,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

frame.add(jScrollPane_userInfo);

jScrollPane_userInfo.setBounds(100, 200, 800, 200);

jScrollPane_userInfo.setFont(new Font("Dialog", 0, 20));

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值