为什么加了JScrollPane不显示??
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Vector;
public class font extends JDialog{
JLabel l1 = new JLabel("字体:");//字体
JLabel l2 = new JLabel("字形:");//字形
JLabel l3 = new JLabel("大小:");//大小
JList jl1 = new JList();
JList jl2 = new JList();
// JList jl3 = new JList();
TextField t1 = new TextField();
TextField t2 = new TextField();
TextField t3 = new TextField();
TextField txt_show = new TextField();//显示示例
JButton bt_ok = new JButton("确定");
JButton bt_cancel = new JButton("取消");
public font(){
//////////////////////////布局//////////////////////////////
this.setTitle("修改字体:");
this.getContentPane().setLayout(null);
l1.setBounds(20,20,50,20);
l2.setBounds(150,20,50,20);
l3.setBounds(280,20,50,20);
String s[] = new String[50];
int j=0;
for(int i=2;i<50;i=i+2)
{
s[j]=""+i;
j++;
}
JList jl3 = new JList(s);
this.getContentPane().add(l1);
this.getContentPane().add(l2);
this.getContentPane().add(l3);
t1.setBounds(20,40,80,20);
t2.setBounds(150,40,80,20);
t3.setBounds(280,40,80,20);
this.getContentPane().add(t1);
this.getContentPane().add(t2);
this.getContentPane().add(t3);
jl1.setBounds(20,70,80,60);
jl2.setBounds(150,70,80,60);
jl3.setBounds(280,70,80,60);
//////为什么加了JScrollPane后jl1不显示??///
this.getContentPane().add(new JScrollPane(jl1));
/////jl2可以显示
this.getContentPane().add(jl2);
this.getContentPane().add(new JScrollPane(jl3));
txt_show.setBounds(150,150,210,80);
this.getContentPane().add(txt_show);
bt_ok.setBounds(380,40,80,25);
bt_cancel.setBounds(380,70,80,25);
this.getContentPane().add(bt_ok);
this.getContentPane().add(bt_cancel);
////////////////////////////////////////////////////////
}
public static void main(String args[])
{
font a = new font();
a.setSize(500,300);
a.show();
}
}
6 个解决方案
#1
up
#2
再顶一下
#3
我在JTextArea中加,今中午毫不容易出来了
outText=new JTextArea();
outText.setText("");
JScrollPane scrollPaneoutText=new JScrollPane(outText);
scrollPaneoutText.setLayout(new ScrollPaneLayout());
scrollPaneoutText.setBounds(310,0,245,360);
c.add(scrollPaneoutText);
outText=new JTextArea();
outText.setText("");
JScrollPane scrollPaneoutText=new JScrollPane(outText);
scrollPaneoutText.setLayout(new ScrollPaneLayout());
scrollPaneoutText.setBounds(310,0,245,360);
c.add(scrollPaneoutText);
#4
解决了
#5
怎么解决的?
#6
估计是定位或大小不对,被首层容器给覆盖了,我经常遇到这种问题!
#1
up
#2
再顶一下
#3
我在JTextArea中加,今中午毫不容易出来了
outText=new JTextArea();
outText.setText("");
JScrollPane scrollPaneoutText=new JScrollPane(outText);
scrollPaneoutText.setLayout(new ScrollPaneLayout());
scrollPaneoutText.setBounds(310,0,245,360);
c.add(scrollPaneoutText);
outText=new JTextArea();
outText.setText("");
JScrollPane scrollPaneoutText=new JScrollPane(outText);
scrollPaneoutText.setLayout(new ScrollPaneLayout());
scrollPaneoutText.setBounds(310,0,245,360);
c.add(scrollPaneoutText);
#4
解决了
#5
怎么解决的?
#6
估计是定位或大小不对,被首层容器给覆盖了,我经常遇到这种问题!