This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
HI All, I'am having problem in getting the index of row once a selection is made.I have implemented all the required methods but still problem persists.
public String getColumnName(int col) { return columns[col]; }
public int getColumnCount() { return columns.length; }
public int getRowCount() { return datalist.size(); }
public Object getValueAt(int row, int col) {
Vector rowList = (Vector)datalist.get(row);
if(rowList.firstElement()!=null) {
switch (col) {
case 0: return (String) rowList.elementAt(0); case 1: return (String) rowList.elementAt(1); case 2: return (String) rowList.elementAt(2); default: return null; } }else return null;
}
// This one method decides exactly which cells are editable. public boolean isCellEditable(int row, int col) { switch (col) {
case 0: //Hostname return false; case 1: //Product Family return false; case 2: //Serial Number return false; default: return false; } }
public Class getColumnClass(int col) { switch (col) {
case 0: //Hostname return String.class; case 1: //Product Family return String.class; case 2: //Serial Number return String.class; default: return null; } }
public void valueChanged(ListSelectionEvent mySelectionEvent) { if (mySelectionEvent.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)mySelectionEvent.getSource(); //Here i wanted to do same action if selection is empty. String hostName; hostName = (String)myTableModel.getValueAt(myTable.getSelectedRow(),0); }
One problem with this code is that you name your variable myTableModel the same as the class myTableModel. The class should start with caps: MyTableModel so it does not conflict with the instance name myTableModel.
Please post the rest of your main class if that doesn't help.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.