Swing JTABLE设置表头行高

Swing JTABLE设置表头行高,第1张

不知道你在讲什么,请贴出代码,setRowHeight()方法本来就是对表格行起作用,你要的是Excel的效果吧,设置某一行作为tableHeader并设置它的样式。这个可以做但是有点麻烦,如果你是这个需求请贴代码。

//创建table

private String[] columnNames=

private Object[][] rowData=new Object[0][4]

private DefaultTableModel tableModel=new DefaultTableModel(rowData,columnNames)

private JTable jTable=new JTable(tableModel)

//设置居中

DefaultTableCellRenderer r = new DefaultTableCellRenderer()

r.setHorizontalAlignment(JLabel.CENTER)

jTable.setDefaultRenderer(Object.class, r)

在netbeans调试运行过啦,改动如下:

(1)最后一句jp7.add(jtable)改成jp0.add(jsp)

(2)你这里JTable jtable = new JTable(new String[][] {

{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}

},

new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" }

欠一半括号,我看不太懂,暂且改成JTable jtable = new JTable(new String[][] {

{"哈","飞","飞","飞","我"," 的","爱情"},{"哈","飞","飞","飞","我"," 的","爱情"}

},

new String[] { "书名", "价格", "出版时间", "入库时间","作家","入库数","书类别" })

(3)B ab = new B()应该加,ab.setVisible(true)

(4)这点只是建议.你里面大量使用的jPassordField可改用jTextField


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11088255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存