Java 单击JTable中的行时出现NullPointerException
如果单击Jtable中的空第8列,我想激活一个按钮。但我明白了:Java 单击JTable中的行时出现NullPointerException,java,swing,jtable,listselectionlistener,Java,Swing,Jtable,Listselectionlistener,如果单击Jtable中的空第8列,我想激活一个按钮。但我明白了: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at records$1.valueChanged(records.java:57) 这是我的密码: tb_records.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at records$1.valueChanged(records.java:57)
这是我的密码:
tb_records.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent event) {
int row = tb_records.getSelectedRow();
DefaultTableModel model = (DefaultTableModel)tb_records.getModel();
String hehe = (String) model.getValueAt(row, 7);
if(!hehe.equals("")) {
b_extend.setEnabled(false);
}
else {
b_extend.setEnabled(true);
}
}
});
(不是答案,我说的是简单的方法)
ListSelectionMode
更改为SINGLE...
,则只能选择一行,否则必须在所选行的数组中循环
如果(行>-1)
==未选择任何行,如果通过,则可以ListSelectionMode
更改为SINGLE...
,则只能选择一行,否则必须在所选行的数组中循环
如果(行>-1)
==未选择任何行,如果通过,则可以ListSelectionMode
更改为SINGLE...
,则只能选择一行,否则必须在所选行的数组中循环
如果(行>-1)
==未选择任何行,如果通过,则可以ListSelectionMode
更改为SINGLE...
,则只能选择一行,否则必须在所选行的数组中循环
如果(行>-1)
==未选择任何行,如果通过,则可以我对您的代码做了一些更改,可能会有所帮助
.(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e) {
if (! e.getValueIsAdjusting() ) {
ListSelectionModel d = (ListSelectionModel)e.getSource();
if(d.getLeadSelectionIndex() != -1){
String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
b_extend.setEnabled("".equals(hehe));
}
}
}
});
我对您的代码做了一些更改,可能会有所帮助
.(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e) {
if (! e.getValueIsAdjusting() ) {
ListSelectionModel d = (ListSelectionModel)e.getSource();
if(d.getLeadSelectionIndex() != -1){
String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
b_extend.setEnabled("".equals(hehe));
}
}
}
});
我对您的代码做了一些更改,可能会有所帮助
.(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e) {
if (! e.getValueIsAdjusting() ) {
ListSelectionModel d = (ListSelectionModel)e.getSource();
if(d.getLeadSelectionIndex() != -1){
String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
b_extend.setEnabled("".equals(hehe));
}
}
}
});
我对您的代码做了一些更改,可能会有所帮助
.(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e) {
if (! e.getValueIsAdjusting() ) {
ListSelectionModel d = (ListSelectionModel)e.getSource();
if(d.getLeadSelectionIndex() != -1){
String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
b_extend.setEnabled("".equals(hehe));
}
}
}
});
@nachokk-if(!hehe.equals(“”){为了更好的帮助,越早发布一个[SSCCE][1],短的,可运行的,可编译的,带有JTable[1]的硬编码值:作为对
“.equals(hehe)
@nachokk-if(!hehe.equals(“”){为了更好的帮助,越早发布一个[SSCCE][1],短的,可运行的,可编译的,带有JTable[1]的硬编码值]:作为快速修复更改为“”.equals(hehe)
@nachokk-if(!hehe.equals(“”){为了更好地帮助,请尽早发布[SSCCE][1],简短、可运行、可编译,带有JTable[1]的硬编码值:作为快速修复更改为“”.equals(hee)
@nachokk-if(!hehe.equals(“”){为了更好地帮助,请尽早发布[SSCCE][1],简短,可运行,可编译,带有JTable[1]的硬编码值:作为对的快速修改。等于(呵呵)