【发布时间】:2017-10-03 12:57:17
【问题描述】:
将我的 JTable(带有列标题的表)添加到 JScrollPane 中,两者都显示良好...
如果相同的 JTable + 一些 JPanel...都添加到主 JPanel(BorderLayout) 然后将此主 JPanel 添加到 JScrollPane ....表格的列标题停止显示而表格显示?!
知道为什么以及如何解决这个问题..
somePanel=new JPanel (new FlowLayout ());
somePanel.setPreferredSize (new Dimension (600,50));
somePanel.setBackground (Color.lightGray);
mainPane=new JPanel (new BorderLayout ());
mainPane.setPreferredSize (new Dimension (600,550));
mainPane.setBackground (Color.lightGray);
mainPane.add (somePanel,BorderLayout.NORTH);
mainPane.add (table,BorderLayout.CENTER);
scrollBar=new JscrollBar();
scrollBar.setVisible (true);
scrollBar.setVisibleAmount (10);
scrollBar.setEnabled (true);
scrollBar.setOrientation (Adjustable.VERTICAL);
scrollPane=new JScrollPane ();
scrollPane.setVerticalScrollBar (scrollBar);
scrollPane.setVerticalScrollBarPolicy
(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize (new Dimension (600,650));
scrollPane.setViewportView (mainPane);
/*the createExamsSchedualTable() is inside inner class in the Jframe
and called by class constructor*/
private void createExamsSchedualTable(){
table=new JTable (new TheTableModel ());
table.setPreferredScrollableViewportSize (new Dimension (600,570));
table.setFillsViewportHeight (true);
table.setAutoResizeMode (JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setAutoCreateRowSorter (true);
table.setSelectionBackground (Color.LIGHT_GRAY);
table.setDragEnabled (true);
table.setGridColor (Color.LIGHT_GRAY);
table.setIntercellSpacing (new Dimension (3,3));
table.setRowSelectionAllowed (true);
table.setColumnSelectionAllowed (true);
table.setCellSelectionEnabled (true);
table.setShowGrid (true);
table.setShowHorizontalLines (true);
table.setVerifyInputWhenFocusTarget (true);
table.setToolTipText ("Exams Scheduals Times Table");
}
/*TheTableModel class extends AbstractTableModel */
【问题讨论】:
-
你能发布你的代码吗?
-
@Chris Phillips ...嗨,我在问题中添加了代码...实际上它的正常代码..仍然不知道为什么标题消失了!!
标签: java swing jtable jpanel jscrollpane