JAVA如何给窗口设计显示的文本框为可选中状态,点击修改按钮后可直接对该条内容进行修改?
2个回答
展开全部
你可以在你做出jTable的内容你面自己做一个提示窗来修改内容。
makeFace(jTable1);
public static void makeFace(JTable table) {
DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.setHorizontalAlignment(JLabel.RIGHT);
return super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}};
for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
}
}
makeFace(jTable1);
public static void makeFace(JTable table) {
DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.setHorizontalAlignment(JLabel.RIGHT);
return super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}};
for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
}
}
追问
我的修改按钮已经有修改功能了,我是想问,如何点击第一条记录的时候,上面的各个文本字段能显示下面文本区域中被选中的记录
追答
public static void makeFace(JTable table) {
DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.setHorizontalAlignment(JLabel.RIGHT);
你可以写在这里= ="
你直接在这里写
System.out.println(column);//这样方便你看点到哪一个
return super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}};
for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询