JAVA中JTable的问题
这是我的程序,有错,高手帮忙改一下啊:importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;public...
这是我的程序,有错,高手帮忙改一下啊:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class A extends JFrame {
public static void main(String args[]) {
B ab = new B();
}
}
public class B extends JFrame{
public void B()
{
JPanel jp=new JPanel();
add(jp);
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JPanel jp4=new JPanel();
JPanel jp5=new JPanel();
JPanel jp6=new JPanel();
JPanel jp7=new JPanel();
JPanel jp8=new JPanel();
JPanel jp9=new JPanel();
JPanel jp0=new JPanel();
jp.add(jp1);
jp.add(jp2);
jp.add(jp3);
jp.add(jp4);
jp.add(jp5);
jp.add(jp6);
jp.add(jp8);
jp.add(jp9);
jp.add(jp0);
setSize(800,800);
setTitle("书的录入");
setVisible(true);
JLabel jb1=new JLabel("书的录入");
jp1.add(jb1);
JLabel jb2=new JLabel("书名");
JPasswordField jt1 = new JPasswordField(10);
jp2.add(jb2);
jp2.add(jt1);
JLabel jb3=new JLabel("价格");
JPasswordField jt2 = new JPasswordField(10);
jp3.add(jb3);
jp3.add(jt2);
JLabel jb4=new JLabel("出版时间");
JPasswordField jt3 = new JPasswordField(10);
jp4.add(jb4);
jp4.add(jt3);
JLabel jb5=new JLabel("入库时间");
JPasswordField jt4 = new JPasswordField(10);
jp5.add(jb5);
jp5.add(jt4);
JLabel jb6=new JLabel("作家");
JPasswordField jt5 = new JPasswordField(10);
jp6.add(jb6);
jp6.add(jt5);
JLabel jb7=new JLabel("入库数");
JPasswordField jt6 = new JPasswordField(10);
jp7.add(jb7);
jp7.add(jt6);
JLabel jb8=new JLabel("类别");
Choice leibie = new Choice();
leibie.add("科幻");
leibie.add("爱情");
leibie.add("恐怖");
leibie.add("侦探");
leibie.add("武侠");
jp8.add(jb8);
jp8.add(leibie);
JButton btn1 = new JButton("增加");
JButton btn2 = new JButton("删除");
jp9.add(btn1);
jp9.add(btn2);
JTable jtable = new JTable(new String[][] {
{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}
},
new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" };
jtable.setRowHeight(25); // 设置行高
jtable.setGridColor(Color.yellow); // 设置边框颜色
JScrollPane jsp = new JScrollPane(jtable);
jtable.setGridColor(Color.yellow);
jsp.setViewportView(jtable);
jp7.add(jtable);
}
}
语法错误我改了,但是不能显示表格,只有其他的内容;还有就是运行的窗口要改边一下大小才能显示东西,要不然就不给显示。高手们,怎么办啊,急啊~~~~~~
答案能运行后马上追50,谢谢
我用的是JCreaor4.0的IDE工具,我运行了后不出现表格,只出现上面的东西,就是没有表格出来,怎么回事啊 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class A extends JFrame {
public static void main(String args[]) {
B ab = new B();
}
}
public class B extends JFrame{
public void B()
{
JPanel jp=new JPanel();
add(jp);
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JPanel jp4=new JPanel();
JPanel jp5=new JPanel();
JPanel jp6=new JPanel();
JPanel jp7=new JPanel();
JPanel jp8=new JPanel();
JPanel jp9=new JPanel();
JPanel jp0=new JPanel();
jp.add(jp1);
jp.add(jp2);
jp.add(jp3);
jp.add(jp4);
jp.add(jp5);
jp.add(jp6);
jp.add(jp8);
jp.add(jp9);
jp.add(jp0);
setSize(800,800);
setTitle("书的录入");
setVisible(true);
JLabel jb1=new JLabel("书的录入");
jp1.add(jb1);
JLabel jb2=new JLabel("书名");
JPasswordField jt1 = new JPasswordField(10);
jp2.add(jb2);
jp2.add(jt1);
JLabel jb3=new JLabel("价格");
JPasswordField jt2 = new JPasswordField(10);
jp3.add(jb3);
jp3.add(jt2);
JLabel jb4=new JLabel("出版时间");
JPasswordField jt3 = new JPasswordField(10);
jp4.add(jb4);
jp4.add(jt3);
JLabel jb5=new JLabel("入库时间");
JPasswordField jt4 = new JPasswordField(10);
jp5.add(jb5);
jp5.add(jt4);
JLabel jb6=new JLabel("作家");
JPasswordField jt5 = new JPasswordField(10);
jp6.add(jb6);
jp6.add(jt5);
JLabel jb7=new JLabel("入库数");
JPasswordField jt6 = new JPasswordField(10);
jp7.add(jb7);
jp7.add(jt6);
JLabel jb8=new JLabel("类别");
Choice leibie = new Choice();
leibie.add("科幻");
leibie.add("爱情");
leibie.add("恐怖");
leibie.add("侦探");
leibie.add("武侠");
jp8.add(jb8);
jp8.add(leibie);
JButton btn1 = new JButton("增加");
JButton btn2 = new JButton("删除");
jp9.add(btn1);
jp9.add(btn2);
JTable jtable = new JTable(new String[][] {
{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}
},
new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" };
jtable.setRowHeight(25); // 设置行高
jtable.setGridColor(Color.yellow); // 设置边框颜色
JScrollPane jsp = new JScrollPane(jtable);
jtable.setGridColor(Color.yellow);
jsp.setViewportView(jtable);
jp7.add(jtable);
}
}
语法错误我改了,但是不能显示表格,只有其他的内容;还有就是运行的窗口要改边一下大小才能显示东西,要不然就不给显示。高手们,怎么办啊,急啊~~~~~~
答案能运行后马上追50,谢谢
我用的是JCreaor4.0的IDE工具,我运行了后不出现表格,只出现上面的东西,就是没有表格出来,怎么回事啊 展开
2个回答
展开全部
在netbeans调试运行过啦,改动如下:
(1)最后一句jp7.add(jtable); 改成jp0.add(jsp);
(2)你这里JTable jtable = new JTable(new String[][] {
{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}
},
new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" };
欠一半括号,我看不太懂,暂且改成JTable jtable = new JTable(new String[][] {
{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}
},
new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" });
(3)B ab = new B(); 应该加,ab.setVisible(true);
(4)这点只是建议.你里面大量使用的jPassordField可改用jTextField
(1)最后一句jp7.add(jtable); 改成jp0.add(jsp);
(2)你这里JTable jtable = new JTable(new String[][] {
{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}
},
new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" };
欠一半括号,我看不太懂,暂且改成JTable jtable = new JTable(new String[][] {
{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}
},
new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" });
(3)B ab = new B(); 应该加,ab.setVisible(true);
(4)这点只是建议.你里面大量使用的jPassordField可改用jTextField
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询