java JTable设置行高和列宽的问题
Stringsql="select*fromequipment";rs=db.getResult(sql);try{rs.beforeFirst();while(rs.n...
String sql="select * from equipment ";
rs=db.getResult(sql);
try
{
rs.beforeFirst();
while(rs.next())
{
Vector tempvector=new Vector(1,1);
tempvector.add(rs.getString(11));
tempvector.add(rs.getString(10));
tempvector.add(rs.getString(7));
model.addRow(tempvector);
}
}
catch(SQLException sqle)
{
System.out.println(sqle);
}
this.setVisible(true);
}
private JTable getShowtable()
{
if (showtable == null)
{
showtable = new JTable(model);
showtable.setRowHeight(50);//设置行高
showtable.setRowHeight(0,80);
showtable.setGridColor(Color.BLUE);
showtable.setRowMargin(5);//设置相邻两行单元格的距离
//showtable.getColumnModel().getColumn(0).setPreferredWidth(80);
//TableColumn column=showtable.getColumnModel().getColumn(0);
//column.setPreferredWidth(100);//设置第一列的宽度
}
return showtable;
}
private JScrollPane getJScrollPane()
{
if (jScrollPane == null)
{
jScrollPane = new JScrollPane();
jScrollPane.setBounds(30, 300, 500, 180);
jScrollPane.setViewportView(getShowtable());
}
return jScrollPane;
}
为何设置第一行行高语句showtable.setRowHeight(0,80);不起作用,并且下面设置列宽的语句执行出错,请指点一下吧 展开
rs=db.getResult(sql);
try
{
rs.beforeFirst();
while(rs.next())
{
Vector tempvector=new Vector(1,1);
tempvector.add(rs.getString(11));
tempvector.add(rs.getString(10));
tempvector.add(rs.getString(7));
model.addRow(tempvector);
}
}
catch(SQLException sqle)
{
System.out.println(sqle);
}
this.setVisible(true);
}
private JTable getShowtable()
{
if (showtable == null)
{
showtable = new JTable(model);
showtable.setRowHeight(50);//设置行高
showtable.setRowHeight(0,80);
showtable.setGridColor(Color.BLUE);
showtable.setRowMargin(5);//设置相邻两行单元格的距离
//showtable.getColumnModel().getColumn(0).setPreferredWidth(80);
//TableColumn column=showtable.getColumnModel().getColumn(0);
//column.setPreferredWidth(100);//设置第一列的宽度
}
return showtable;
}
private JScrollPane getJScrollPane()
{
if (jScrollPane == null)
{
jScrollPane = new JScrollPane();
jScrollPane.setBounds(30, 300, 500, 180);
jScrollPane.setViewportView(getShowtable());
}
return jScrollPane;
}
为何设置第一行行高语句showtable.setRowHeight(0,80);不起作用,并且下面设置列宽的语句执行出错,请指点一下吧 展开
若以下回答无法解决问题,邀请你更新回答
2个回答
展开全部
//创建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);
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);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
布局是什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询