带有JScrollPane的表不会显示列标题

时间:2016-09-26 07:13:41

标签: java swing header jtable jscrollpane

JTable JScrollPane package jTable; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class Main { JFrame frame ; Main() { frame = new JFrame() ; String [][] names = { {"1000","yamen","develeoper"}, {"2000","aymen","data entry"}, {"3000","mohammed","teacher"} }; String[] header = {"ID","NAME","JOB"}; JTable jtb = new JTable(names,header) ; JScrollPane s = new JScrollPane(jtb); jtb.setBounds(40,50,300,400); frame.add(jtb); frame.setSize(400, 500); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new Main(); } } 不会显示列标题。

if($this->request->is('post'))
        {  
            $this->request->data["Leave"]["empid"] = $this->request->data["id"];  
            $this->Leave->empid = $this->request->data["Leave"]["empid"];  
            $this->request->data["Leave"]["leave_start"] = $this->request->data["start_date"];  
            $this->request->data["Leave"]["leave_end"] = $this->request->data["end_date"];  
            $this->request->data["Leave"]["leave_taken"] = $this->request->data["leave_taken"]; 

            if($this->Leave->save($this->request->data['Leave']))
            {
                return $this->redirect(array('action' => 'manage_leave'));
            }
        }

2 个答案:

答案 0 :(得分:4)

滚动窗格将显示标题。使用JScrollPane创建了JTable

JTable jtb = new JTable(names, header);
JScrollPane s = new JScrollPane(jtb);
你可能意味着,

frame.add(s);

有关详细信息,请参阅How to Use Tables: Adding a Table to a Container

table image

答案 1 :(得分:0)

尝试使用名称和标题创建TableModel

tableModel = new DefaultTableModel(names, headers);

然后分配JTableTableModel

jtb.setModel(tableModel);

然后在框架中添加新的JScrollPane

frame.add(new JScrollPane(jtb));

至少,这就是我在程序中的表现。