dimanche 15 mai 2016

JTable dynamically show row headers or colum header

public class MyTableViewer extends MyParentViewer {

private JScrollPane scrollPanel = null;
private MyCustomTable table = null;

public MyTableViewer() {
  table = new MyCustomTable();
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);


  // add an selection listener for detecting the selected TestcaseIDs
final ListSelectionModel selectionModel = table.getSelectionModel();
if (selectionModel != null) {
  selectionModel.addListSelectionListener(new ListSelectionListener() {

    @Override
    public void valueChanged(ListSelectionEvent e) {
      // react on completed selection changes only
      if (!e.getValueIsAdjusting()) { 

       //some code...
      }

    }
  }
}

scrollPanel = new JScrollPane(table);

final JTableHeader tableHeader = table.getTableHeader();
tableHeader.addMouseListener(getMousePressedDelegate());

}
}

public class MyParentViewer extends JPanel {
...
}
public class MyCustomTable extends MyTable {

....
}

public class MyTable extends AbstractMyTable {
...
}

public class AbstractMyTable extends JTable {
...
}

Depending on the condition, I want my table to show headers at the row instead of column. Could anyone give me idea how to proceed. Should I override the method in JTable, configureEnclosingScrollPane().?

I have searched the forums and see different interpretations. I am totally lost. I am confused with the design. Could anyone help me.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire