java Swing 加入一个滚动条后不出东西了,为什么
为什么我的hellocontent不显示了???publicclassLoadingextendsJDialog{privatestaticfinallongserial...
为什么我的hello content不显示了???
public class Loading extends JDialog{
private static final long serialVersionUID = 1L;
private JPanel textPanel;
private JPanel inButPanel;
private JTextArea jtaTitle;
private JScrollPane jspContent;
private JTextArea jtaContent;
private JButton jbtPre;
private JButton jbtNext;
private JButton jbtSave;
private String titleNum="(1) ";
public Loading(JFrame jf){
super(jf,true);
setBounds(400,100,400,600);
setLayout(new BorderLayout());
textPanel=new JPanel();
textPanel.setLayout(null);
jtaTitle=new JTextArea("hello title");
jtaTitle.setLineWrap(true);
jtaTitle.setEditable(false);
jtaTitle.setText(titleNum+jtaTitle.getText());
jtaTitle.setBounds(0,0,400,60);
jtaTitle.setFont(new Font("Arial",Font.PLAIN,14));
textPanel.add(jtaTitle,BorderLayout.NORTH);
jtaContent=new JTextArea();
jtaContent.setText("hell content");
jspContent=new JScrollPane();
jspContent.setBounds(0,60,390,470);
jspContent.add(jtaContent);
textPanel.add(jspContent);
inButPanel=new JPanel();
jbtPre=new JButton("上一篇");
jbtNext=new JButton("下一篇");
jbtSave=new JButton("保存");
inButPanel.add(jbtPre);
inButPanel.add(jbtNext);
inButPanel.add(jbtSave);
inButPanel.setBounds(0,530,400,70);
textPanel.add(inButPanel,BorderLayout.SOUTH);
add(textPanel,BorderLayout.CENTER);
setTitle("段落验证");
setVisible(true);
setBackground(new Color(Integer.decode("#f5f6f0")));
}
public static void main(String[] args) {
new Loading(null);
}
} 展开
public class Loading extends JDialog{
private static final long serialVersionUID = 1L;
private JPanel textPanel;
private JPanel inButPanel;
private JTextArea jtaTitle;
private JScrollPane jspContent;
private JTextArea jtaContent;
private JButton jbtPre;
private JButton jbtNext;
private JButton jbtSave;
private String titleNum="(1) ";
public Loading(JFrame jf){
super(jf,true);
setBounds(400,100,400,600);
setLayout(new BorderLayout());
textPanel=new JPanel();
textPanel.setLayout(null);
jtaTitle=new JTextArea("hello title");
jtaTitle.setLineWrap(true);
jtaTitle.setEditable(false);
jtaTitle.setText(titleNum+jtaTitle.getText());
jtaTitle.setBounds(0,0,400,60);
jtaTitle.setFont(new Font("Arial",Font.PLAIN,14));
textPanel.add(jtaTitle,BorderLayout.NORTH);
jtaContent=new JTextArea();
jtaContent.setText("hell content");
jspContent=new JScrollPane();
jspContent.setBounds(0,60,390,470);
jspContent.add(jtaContent);
textPanel.add(jspContent);
inButPanel=new JPanel();
jbtPre=new JButton("上一篇");
jbtNext=new JButton("下一篇");
jbtSave=new JButton("保存");
inButPanel.add(jbtPre);
inButPanel.add(jbtNext);
inButPanel.add(jbtSave);
inButPanel.setBounds(0,530,400,70);
textPanel.add(inButPanel,BorderLayout.SOUTH);
add(textPanel,BorderLayout.CENTER);
setTitle("段落验证");
setVisible(true);
setBackground(new Color(Integer.decode("#f5f6f0")));
}
public static void main(String[] args) {
new Loading(null);
}
} 展开
1个回答
展开全部
楼主,添加滚动条要这么写
jspContent=new JScrollPane(jtaContent);//这里传入要添加滚动条的控件
jspContent.setBounds(0,60,390,470);
//jspContent.add(jtaContent); 这句不要
要想将控件与JScrollPane关联起来,不能用add方法,必须使用setViewportView,使用add添加的话JScrollPane是不会显示的,也不会关联滚动功能
所以楼主也可以将jspContent.add(jtaContent); 改成jspContent.setViewportView(jtaContent);
希望能帮到楼主
jspContent=new JScrollPane(jtaContent);//这里传入要添加滚动条的控件
jspContent.setBounds(0,60,390,470);
//jspContent.add(jtaContent); 这句不要
要想将控件与JScrollPane关联起来,不能用add方法,必须使用setViewportView,使用add添加的话JScrollPane是不会显示的,也不会关联滚动功能
所以楼主也可以将jspContent.add(jtaContent); 改成jspContent.setViewportView(jtaContent);
希望能帮到楼主
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询