java JTable中的标题栏不显示问题

刚学JTable ,用来写图书馆系统,部分代码(代码很不全,事件处理也没写。。。望见谅!!)如下

import javax.swing.*;
import javax.swing.border.LineBorder;

import java.awt.*;
import java.awt.event.*;
public class BookManagePanel extends JPanel implements ActionListener{
   private JPanel bookInfoPanel;
      private JComboBox choiceComboBox;
      private JTextField inputField;
      private JButton inq_bt,add_bt,can_bt;
      private JTable bookTable;
      String[] title={"编号","书名","作者","是否珍本","是否可借"};
      String[] choice={"书名","ISBN","编号","作者","出版社"};
      final String[][] bookDate={
        {"1","JAVA","谢福恒","是","可借"}
      };
     
      public BookManagePanel(){
       setLayout(null);
       bookInfoPanel=new JPanel();
       choiceComboBox=new JComboBox();
       inputField=new JTextField("请输入要查找的书的相关信息");
       inq_bt=new JButton("查找");
          add_bt=new JButton("添加图书");
          can_bt=new JButton("删除图书");
          bookTable=new JTable(bookDate,title);
         
          bookInfoPanel.setBorder(new LineBorder(Color.BLUE));
         
          for(int i=0;i          choiceComboBox.addItem(choice[i]);
          }
         
          inputField.setEditable(true);
         
          choiceComboBox.setBounds(140, 30, 70, 30);
          inputField.setBounds(225, 30, 160, 30);
          inq_bt.setBounds(395, 30, 60, 30);
          bookInfoPanel.setBounds(50, 80, 480, 300);
          add_bt.setBounds(180, 390, 120, 30);
          can_bt.setBounds(330, 390, 120, 30);
         
       
          inq_bt.addActionListener(this);
          add_bt.addActionListener(this);
          can_bt.addActionListener(this);
         
          bookInfoPanel.add(bookTable,BorderLayout.CENTER);
          add(inputField);
          add(choiceComboBox);
          add(bookInfoPanel);
          add(inq_bt);
       add(add_bt);
       add(can_bt);
      }
     
     
      public void actionPerformed(ActionEvent e){
      
      }
}

发现title并没有在JTable上显示,很蛋疼,搞了好久没搞定,最后问了高手才知道要把JTable放在Jscrollpane中才可以,中间有部分代码改成

          inq_bt.addActionListener(this);
          add_bt.addActionListener(this);
          can_bt.addActionListener(this);
         
          JScrollPane js = new JScrollPane(bookTable);
          js.setPreferredSize(new Dimension(475,295));
         
          bookInfoPanel.add(js,BorderLayout.CENTER);
          add(inputField);
          add(choiceComboBox);

就可以了。

看来学习软件一定要多向大牛请教哇,各种顿悟!!!

你可能感兴趣的:(java JTable中的标题栏不显示问题)