问题描述
import java.awt.Color;import java.awt.Dimension;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.table.DefaultTableModel;public class TableRightTest extends JFrame{//private JPanel jp; public TableRightTest(){ this.setSize(800, 500); this.setLocation(250, 150); this.setLayout(null); this.setResizable(false); this.setVisible(true); this.initTable(); } private JTable tbl_query;private DefaultTableModel defaultTblModel;private int tableColumn=9;private void initTable() {String[] columnNames= new String[tableColumn];Object[][] data={};DefaultTableModel dmodel = new DefaultTableModel(data,columnNames);defaultTblModel = dmodel;tbl_query = new JTable(dmodel);tbl_query.setPreferredScrollableViewportSize(new Dimension(30, 30));tbl_query.setBounds(1, 1, 699, 160);JScrollPane jsp = new JScrollPane();jsp.setLayout(null);jsp.setBounds(50, 150, 700, 200);jsp.setVisible(true);jsp.setBackground(new Color(120,145,152));jsp.add(tbl_query);this.add(jsp);initTableData();}private void initTableData() {// TODO Auto-generated method stubfor(int j=0;j<3;j++){String[] arr = new String[tableColumn];for(int i=0;i<tableColumn;i++){arr[i]= "A"+i;}defaultTblModel.addRow(arr);}}public static void main(String[] args) {new TableRightTest();}} 问题补充:jobar 写道
解决方案
如果是表头参照一下:http://liuqing-2010-07.iteye.com/blog/994858如果是其他标题需要用JLable的哟!
解决方案二:
你说的是Jtable的表头吧 而不是标题?
解决方案三:
public TableRightTest() {this.setSize(800, 500);this.setLocation(250, 150);this.setLayout(null);this.setResizable(false);this.setVisible(true);this.initTable();this.setTitle("hello");//设置标题?}