java swing里,如何在一个表格中的某几个单元格中添加按钮?想各位大牛们请教~~
getColumnModel().getColumn(1).setCellRenderer()的方法我知道~~可是这只能对某一列全部添加按钮。我需要在特定的某些行某些列添...
getColumnModel().getColumn(1).setCellRenderer()的方法我知道~~可是这只能对某一列全部添加按钮。我需要在特定的某些行某些列添加,并且能够设定特定的某个按钮的属性~~~网上找了好多都找不到~~~~跪求大牛们的帮助!!
展开
展开全部
public class NewClass {
public static void main(String[] args) {
JFrame frame = new JFrame();
final JTable table = new JTable(4, 4) {
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (row == 1 && column == 1) {
return new DefaultCellEditor(new JCheckBox());
}
return super.getCellEditor(row, column);
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
if (row == 1 && column == 1) {
return new TableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
return new JCheckBox();
}
};
}
return super.getCellRenderer(row, column);
}
};
frame.getContentPane().add(table, BorderLayout.CENTER);
frame.setDefaultCloseOperation(3);
frame.setVisible(true);
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
final JTable table = new JTable(4, 4) {
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (row == 1 && column == 1) {
return new DefaultCellEditor(new JCheckBox());
}
return super.getCellEditor(row, column);
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
if (row == 1 && column == 1) {
return new TableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
return new JCheckBox();
}
};
}
return super.getCellRenderer(row, column);
}
};
frame.getContentPane().add(table, BorderLayout.CENTER);
frame.setDefaultCloseOperation(3);
frame.setVisible(true);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
LZ这问题问的好,列好弄,行这个问题确实还不知道如何解决.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询