java中jtable可以看见表格内容,但是看不到列名.怎么办呢?
还有个小毛病,就是每次都得最大化后才能看见数据,能不能请顺便解决下代码如下:importjava.awt.*;importjava.awt.event.*;importj...
还有个小毛病,就是每次都得最大化后才能看见数据,能不能请顺便解决下
代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class aa extends JFrame{
public static void main(String args[]){
bb ab=new bb();
}
}
class bb extends JFrame{
public bb(){
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();
jp.add(jp1);
jp.add(jp2);
jp.add(jp3);
jp.add(jp4);
jp.add(jp5);
jp.add(jp6);
jp.add(jp7);
jp.setLayout(new GridLayout(7,1));
setSize(450,450);
setTitle("查询产品");
setVisible(true);
JLabel jl1=new JLabel("查询产品");
jp1.add(jl1);
JLabel jl2=new JLabel("产品ID:");
Choice ch=new Choice();
ch.add("0000");
ch.add("0001");
jp2.add(jl2);
jp2.add(ch);
JLabel jl3=new JLabel("产品名称:");
JPasswordField jt2=new JPasswordField(10);
jp3.add(jl3);
jp3.add(jt2);
JLabel jl4=new JLabel("产品型号:");
JTextField jt3=new JTextField(10);
jp4.add(jl4);
jp4.add(jt3);
JLabel jl5=new JLabel("产品单价:");
JTextField jt4=new JTextField(10);
jp5.add(jl5);
jp5.add(jt4);
JButton jb1=new JButton("确定");
JButton jb2=new JButton("取消");
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bb.this.dispose();
}
});
jp6.add(jb1);
jp6.add(jb2);
JTable jtable=new JTable(new String[][]{{"0001","柿子","蔬菜","1"},
{"0002","茄子","蔬菜","2"},
{"0003","西瓜","水果","3"},
{"0004","黄瓜","蔬菜","4"}},new String[]{"产品ID","产品名称","产品型号","产品单价"});
jtable.setRowHeight(25); //设置行高
jtable.setGridColor(Color.yellow); //设置边框颜色
JScrollPane jsp=new JScrollPane(jtable);
getContentPane().add(jsp,BorderLayout.CENTER);
jtable.getTableHeader().setReorderingAllowed(false);//设置列不可移动
jp7.add(jtable);
}
} 展开
代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class aa extends JFrame{
public static void main(String args[]){
bb ab=new bb();
}
}
class bb extends JFrame{
public bb(){
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();
jp.add(jp1);
jp.add(jp2);
jp.add(jp3);
jp.add(jp4);
jp.add(jp5);
jp.add(jp6);
jp.add(jp7);
jp.setLayout(new GridLayout(7,1));
setSize(450,450);
setTitle("查询产品");
setVisible(true);
JLabel jl1=new JLabel("查询产品");
jp1.add(jl1);
JLabel jl2=new JLabel("产品ID:");
Choice ch=new Choice();
ch.add("0000");
ch.add("0001");
jp2.add(jl2);
jp2.add(ch);
JLabel jl3=new JLabel("产品名称:");
JPasswordField jt2=new JPasswordField(10);
jp3.add(jl3);
jp3.add(jt2);
JLabel jl4=new JLabel("产品型号:");
JTextField jt3=new JTextField(10);
jp4.add(jl4);
jp4.add(jt3);
JLabel jl5=new JLabel("产品单价:");
JTextField jt4=new JTextField(10);
jp5.add(jl5);
jp5.add(jt4);
JButton jb1=new JButton("确定");
JButton jb2=new JButton("取消");
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bb.this.dispose();
}
});
jp6.add(jb1);
jp6.add(jb2);
JTable jtable=new JTable(new String[][]{{"0001","柿子","蔬菜","1"},
{"0002","茄子","蔬菜","2"},
{"0003","西瓜","水果","3"},
{"0004","黄瓜","蔬菜","4"}},new String[]{"产品ID","产品名称","产品型号","产品单价"});
jtable.setRowHeight(25); //设置行高
jtable.setGridColor(Color.yellow); //设置边框颜色
JScrollPane jsp=new JScrollPane(jtable);
getContentPane().add(jsp,BorderLayout.CENTER);
jtable.getTableHeader().setReorderingAllowed(false);//设置列不可移动
jp7.add(jtable);
}
} 展开
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class aa extends JFrame {
public static void main(String args[]) {
bb ab = new bb();
}
}
class bb extends JFrame {
public bb() {
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();
jp.add(jp1);
jp.add(jp2);
jp.add(jp3);
jp.add(jp4);
jp.add(jp5);
jp.add(jp6);
jp.add(jp7);
jp.setLayout(new GridLayout(7, 1));
setSize(450, 450);
setTitle("查询产品");
setVisible(true);
JLabel jl1 = new JLabel("查询产品");
jp1.add(jl1);
JLabel jl2 = new JLabel("产品ID:");
Choice ch = new Choice();
ch.add("0000");
ch.add("0001");
jp2.add(jl2);
jp2.add(ch);
JLabel jl3 = new JLabel("产品名称:");
JPasswordField jt2 = new JPasswordField(10);
jp3.add(jl3);
jp3.add(jt2);
JLabel jl4 = new JLabel("产品型号:");
JTextField jt3 = new JTextField(10);
jp4.add(jl4);
jp4.add(jt3);
JLabel jl5 = new JLabel("产品单价:");
JTextField jt4 = new JTextField(10);
jp5.add(jl5);
jp5.add(jt4);
JButton jb1 = new JButton("确定");
JButton jb2 = new JButton("取消");
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bb.this.dispose();
}
});
jp6.add(jb1);
jp6.add(jb2);
JTable jtable = new JTable(new String[][] {
{ "0001", "柿子", "蔬菜", "1" }, { "0002", "茄子", "蔬菜", "2" },
{ "0003", "西瓜", "水果", "3" }, { "0004", "黄瓜", "蔬菜", "4" } },
new String[] { "产品ID", "产品名称", "产品型号", "产品单价" });
jtable.setRowHeight(25); // 设置行高
jtable.setGridColor(Color.yellow); // 设置边框颜色
JScrollPane jsp = new JScrollPane();
jsp.setViewportView(jtable);
//getContentPane().add(jsp, BorderLayout.CENTER);
jtable.getTableHeader().setReorderingAllowed(false);// 设置列不可移动
jp7.add(jsp);
}
}
import java.awt.event.*;
import javax.swing.*;
public class aa extends JFrame {
public static void main(String args[]) {
bb ab = new bb();
}
}
class bb extends JFrame {
public bb() {
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();
jp.add(jp1);
jp.add(jp2);
jp.add(jp3);
jp.add(jp4);
jp.add(jp5);
jp.add(jp6);
jp.add(jp7);
jp.setLayout(new GridLayout(7, 1));
setSize(450, 450);
setTitle("查询产品");
setVisible(true);
JLabel jl1 = new JLabel("查询产品");
jp1.add(jl1);
JLabel jl2 = new JLabel("产品ID:");
Choice ch = new Choice();
ch.add("0000");
ch.add("0001");
jp2.add(jl2);
jp2.add(ch);
JLabel jl3 = new JLabel("产品名称:");
JPasswordField jt2 = new JPasswordField(10);
jp3.add(jl3);
jp3.add(jt2);
JLabel jl4 = new JLabel("产品型号:");
JTextField jt3 = new JTextField(10);
jp4.add(jl4);
jp4.add(jt3);
JLabel jl5 = new JLabel("产品单价:");
JTextField jt4 = new JTextField(10);
jp5.add(jl5);
jp5.add(jt4);
JButton jb1 = new JButton("确定");
JButton jb2 = new JButton("取消");
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bb.this.dispose();
}
});
jp6.add(jb1);
jp6.add(jb2);
JTable jtable = new JTable(new String[][] {
{ "0001", "柿子", "蔬菜", "1" }, { "0002", "茄子", "蔬菜", "2" },
{ "0003", "西瓜", "水果", "3" }, { "0004", "黄瓜", "蔬菜", "4" } },
new String[] { "产品ID", "产品名称", "产品型号", "产品单价" });
jtable.setRowHeight(25); // 设置行高
jtable.setGridColor(Color.yellow); // 设置边框颜色
JScrollPane jsp = new JScrollPane();
jsp.setViewportView(jtable);
//getContentPane().add(jsp, BorderLayout.CENTER);
jtable.getTableHeader().setReorderingAllowed(false);// 设置列不可移动
jp7.add(jsp);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询