JTable header : text = two-rows, onClick action = sorting

Hi guys.
I want to create a JTable where the user can have the data sorted by clicking upon a column's header. The code below shows the table I describe (you can click upon a column and sorting is performed).
import javax.swing.JFrame;
import java.awt.HeadlessException;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
//--------- TableSorter ----------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;
//---------- Table Height - Column Width
import javax.swing.table.TableColumn;
import java.awt.FontMetrics;
import javax.swing.JTable;
import java.awt.Dimension;
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
public class Test extends JFrame {
  JPanel jPanel1 = new JPanel();
  JPanel jPanel2 = new JPanel();
  JButton jButton1 = new JButton();
  FlowLayout flowLayout1 = new FlowLayout();
  BorderLayout borderLayout1 = new BorderLayout();
  BorderLayout borderLayout2 = new BorderLayout();
  //------------- MY VARIABLES -------------
  String[] columnNames_objectArr = new String[] {
      "Col1",
      "Column 2",
      "Column 3",
      "C4",
      "Col5",
      "Col 6",
  Vector columnNames_vector = new Vector();
  private Vector data_vector = new Vector();
  private Object[][] data_objectArr;
  public TableHeight_ColumnWidth tcw;
  private int totalTableWidth = 0, totalTableHeight = 0;
  private JComboBox jcmbxData = new JComboBox(
      new String[] {"Not Configured", "Switch", "Modem"});
  private int maxVisibleRows = 51;
  TableSorter model;
  private JTable table;
  JScrollPane jScrollPane1;
  public Test(String[] args) throws HeadlessException {
    try {
      jbInit();
      setupGUI();
      launchGUI();
    catch(Exception e) {
      e.printStackTrace();
  private void jbtnClose_actionPerformed(ActionEvent e) {
    dispose();
  private void launchGUI() {
    pack();
    setVisible(true);
    setResizable(false);
  private void setupGUI() {
    columnNames_vector.addElement("Col1");
    columnNames_vector.addElement("Column 2");
    columnNames_vector.addElement("Column 3");
    columnNames_vector.addElement("C4");
    columnNames_vector.addElement("Col5");
    columnNames_vector.addElement("Col 6");
    Vector row_data1 = new Vector();
    Vector row_data2 = new Vector();
    Vector row_data3 = new Vector();
    Vector row_data4 = new Vector();
    Vector row_data5 = new Vector();
    Vector row_data6 = new Vector();
    row_data1.add("Mary");
    row_data1.add("Campioneato");
    row_data1.add("Snowboarding");
    row_data1.add(new Integer(578987899));
    row_data1.add(new Boolean(false));
    row_data1.add("Not Configured");
    row_data2.add("Alison");
    row_data2.add("Huml");
    row_data2.add("Rowing");
    row_data2.add(new Integer(3));
    row_data2.add(new Boolean(true));
    row_data2.add("Switch");
    row_data3.add("Ka");
    row_data3.add("Walrath");
    row_data3.add("Knitting");
    row_data3.add(new Integer(2));
    row_data3.add(new Boolean(false));
    row_data3.add("Modem");
    row_data4.add("Sharon");
    row_data4.add("Zakhouras");
    row_data4.add("Speed reading");
    row_data4.add(new Integer(20));
    row_data4.add(new Boolean(true));
    row_data4.add("Switch");
    row_data5.add("Philip");
    row_data5.add("Milner");
    row_data5.add("Pool");
    row_data5.add(new Integer(10));
    row_data5.add(new Boolean(false));
    row_data5.add("Not Configured");
    data_vector.add(row_data1);
    data_vector.add(row_data2);
    data_vector.add(row_data3);
    data_vector.add(row_data4);
    data_vector.add(row_data5);
    model = new TableSorter(new SortTableModel(data_vector, columnNames_vector));
    table = new JTable(model);
    tcw = new TableHeight_ColumnWidth(model, table);
    jScrollPane1 = new JScrollPane(table);
    model.setTableHeader(table.getTableHeader());
    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
    //Add a JComboBox as a cellEditor...
    DefaultCellEditor dce = new DefaultCellEditor(jcmbxData);
    table.getColumnModel().getColumn(5).setCellEditor(dce);
    //..... add the IPJPanel as cellEditor.....
    tcw.fixTableLook(maxVisibleRows);
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(borderLayout2);
    jPanel1.setLayout(borderLayout1);
    jPanel2.setLayout(flowLayout1);
    jButton1.setText("Close");
    jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
    jPanel2.add(jButton1, null);
    jButton1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jbtnClose_actionPerformed(e);
  public static void main( String[] args ) {
    new Test(args);
  public boolean getScrollableTracksViewportHeight() {
    Component parent = getParent();
    if (parent instanceof JViewport) {
      return parent.getHeight() > getPreferredSize().height;
    return false;
  //------------------ MY TABLE MODEL ------------------
  public class SortTableModel extends DefaultTableModel {
    private boolean DEBUG = false;
    public SortTableModel(Object[][] data, String[] columnNames) {
      super(data, columnNames);
    public SortTableModel(Vector data, Vector columnNames) {
      super(data, columnNames);
  //------------------ TABLE SORTER -----------------------
  public class TableSorter extends AbstractTableModel {
      protected TableModel tableModel;
      public static final int DESCENDING = -1;
      public static final int NOT_SORTED = 0;
      public static final int ASCENDING = 1;
      private Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);
      public final Comparator COMPARABLE_COMAPRATOR = new Comparator() {
          public int compare(Object o1, Object o2) {
              return ((Comparable) o1).compareTo(o2);
      public final Comparator LEXICAL_COMPARATOR = new Comparator() {
          public int compare(Object o1, Object o2) {
              return o1.toString().compareTo(o2.toString());
      private Row[] viewToModel;
      private int[] modelToView;
      private JTableHeader tableHeader;
      private MouseListener mouseListener;
      private TableModelListener tableModelListener;
      private Map columnComparators = new HashMap();
      private List sortingColumns = new ArrayList();
      public TableSorter() {
          this.mouseListener = new MouseHandler();
          this.tableModelListener = new TableModelHandler();
      public TableSorter(TableModel tableModel) {
          this();
          setTableModel(tableModel);
      public TableSorter(TableModel tableModel, JTableHeader tableHeader) {
          this();
          setTableHeader(tableHeader);
          setTableModel(tableModel);
      private void clearSortingState() {
          viewToModel = null;
          modelToView = null;
      public TableModel getTableModel() {
          return tableModel;
      public void setTableModel(TableModel tableModel) {
          if (this.tableModel != null) {
              this.tableModel.removeTableModelListener(tableModelListener);
          this.tableModel = tableModel;
          if (this.tableModel != null) {
              this.tableModel.addTableModelListener(tableModelListener);
          clearSortingState();
          fireTableStructureChanged();
      public JTableHeader getTableHeader() {
          return tableHeader;
      public void setTableHeader(JTableHeader tableHeader) {
          if (this.tableHeader != null) {
              this.tableHeader.removeMouseListener(mouseListener);
              TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
              if (defaultRenderer instanceof SortableHeaderRenderer) {
                  this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
          this.tableHeader = tableHeader;
          if (this.tableHeader != null) {
              this.tableHeader.addMouseListener(mouseListener);
              this.tableHeader.setDefaultRenderer(
                      new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
      public boolean isSorting() {
          return sortingColumns.size() != 0;
      private Directive getDirective(int column) {
          for (int i = 0; i < sortingColumns.size(); i++) {
              Directive directive = (Directive)sortingColumns.get(i);
              if (directive.column == column) {
                  return directive;
          return EMPTY_DIRECTIVE;
      public int getSortingStatus(int column) {
          return getDirective(column).direction;
      private void sortingStatusChanged() {
          clearSortingState();
          fireTableDataChanged();
          if (tableHeader != null) {
              tableHeader.repaint();
      public void setSortingStatus(int column, int status) {
          Directive directive = getDirective(column);
          if (directive != EMPTY_DIRECTIVE) {
              sortingColumns.remove(directive);
          if (status != NOT_SORTED) {
              sortingColumns.add(new Directive(column, status));
          sortingStatusChanged();
      protected Icon getHeaderRendererIcon(int column, int size) {
          Directive directive = getDirective(column);
          if (directive == EMPTY_DIRECTIVE) {
              return null;
          return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
      private void cancelSorting() {
          sortingColumns.clear();
          sortingStatusChanged();
      public void setColumnComparator(Class type, Comparator comparator) {
          if (comparator == null) {
              columnComparators.remove(type);
          } else {
              columnComparators.put(type, comparator);
      protected Comparator getComparator(int column) {
          Class columnType = tableModel.getColumnClass(column);
          Comparator comparator = (Comparator) columnComparators.get(columnType);
          if (comparator != null) {
              return comparator;
          if (Comparable.class.isAssignableFrom(columnType)) {
              return COMPARABLE_COMAPRATOR;
          return LEXICAL_COMPARATOR;
      private Row[] getViewToModel() {
          if (viewToModel == null) {
              int tableModelRowCount = tableModel.getRowCount();
              viewToModel = new Row[tableModelRowCount];
              for (int row = 0; row < tableModelRowCount; row++) {
                  viewToModel[row] = new Row(row);
              if (isSorting()) {
                  Arrays.sort(viewToModel);
          return viewToModel;
      public int modelIndex(int viewIndex) {
          return getViewToModel()[viewIndex].modelIndex;
      private int[] getModelToView() {
          if (modelToView == null) {
              int n = getViewToModel().length;
              modelToView = new int[n];
              for (int i = 0; i < n; i++) {
                  modelToView[modelIndex(i)] = i;
          return modelToView;
      // TableModel interface methods
      public int getRowCount() {
          return (tableModel == null) ? 0 : tableModel.getRowCount();
      public int getColumnCount() {
          return (tableModel == null) ? 0 : tableModel.getColumnCount();
      public String getColumnName(int column) {
          return tableModel.getColumnName(column);
      public Class getColumnClass(int column) {
          return tableModel.getColumnClass(column);
      public boolean isCellEditable(int row, int column) {
          return tableModel.isCellEditable(modelIndex(row), column);
      public Object getValueAt(int row, int column) {
          return tableModel.getValueAt(modelIndex(row), column);
      public void setValueAt(Object aValue, int row, int column) {
          tableModel.setValueAt(aValue, modelIndex(row), column);
      // Helper classes
      private class Row implements Comparable {
          private int modelIndex;
          public Row(int index) {
              this.modelIndex = index;
          public int compareTo(Object o) {
              int row1 = modelIndex;
              int row2 = ((Row) o).modelIndex;
              for (Iterator it = sortingColumns.iterator(); it.hasNext();) {
                  Directive directive = (Directive) it.next();
                  int column = directive.column;
                  Object o1 = tableModel.getValueAt(row1, column);
                  Object o2 = tableModel.getValueAt(row2, column);
                  int comparison = 0;
                  // Define null less than everything, except null.
                  if (o1 == null && o2 == null) {
                      comparison = 0;
                  } else if (o1 == null) {
                      comparison = -1;
                  } else if (o2 == null) {
                      comparison = 1;
                  } else {
                      comparison = getComparator(column).compare(o1, o2);
                  if (comparison != 0) {
                      return directive.direction == DESCENDING ? -comparison : comparison;
              return 0;
      private class TableModelHandler implements TableModelListener {
          public void tableChanged(TableModelEvent e) {
              // If we're not sorting by anything, just pass the event along.
              if (!isSorting()) {
                  clearSortingState();
                  fireTableChanged(e);
                  return;
              // If the table structure has changed, cancel the sorting; the
              // sorting columns may have been either moved or deleted from
              // the model.
              if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                  cancelSorting();
                  fireTableChanged(e);
                  return;
              // We can map a cell event through to the view without widening
              // when the following conditions apply:
              // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
              // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
              // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
              // d) a reverse lookup will not trigger a sort (modelToView != null)
              // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
              // The last check, for (modelToView != null) is to see if modelToView
              // is already allocated. If we don't do this check; sorting can become
              // a performance bottleneck for applications where cells
              // change rapidly in different parts of the table. If cells
              // change alternately in the sorting column and then outside of
              // it this class can end up re-sorting on alternate cell updates -
              // which can be a performance problem for large tables. The last
              // clause avoids this problem.
              int column = e.getColumn();
              if (e.getFirstRow() == e.getLastRow()
                      && column != TableModelEvent.ALL_COLUMNS
                      && getSortingStatus(column) == NOT_SORTED
                      && modelToView != null) {
                  int viewIndex = getModelToView()[e.getFirstRow()];
                  fireTableChanged(new TableModelEvent(TableSorter.this,
                                                       viewIndex, viewIndex,
                                                       column, e.getType()));
                  return;
              // Something has happened to the data that may have invalidated the row order.
              clearSortingState();
              fireTableDataChanged();
              return;
      private class MouseHandler extends MouseAdapter {
          public void mouseClicked(MouseEvent e) {
              JTableHeader h = (JTableHeader) e.getSource();
              TableColumnModel columnModel = h.getColumnModel();
              int viewColumn = columnModel.getColumnIndexAtX(e.getX());
              int column = columnModel.getColumn(viewColumn).getModelIndex();
              if (column != -1) {
                  int status = getSortingStatus(column);
                  if (!e.isControlDown()) {
                      cancelSorting();
                  // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                  // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                  status = status + (e.isShiftDown() ? -1 : 1);
                  status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                  setSortingStatus(column, status);
      private class Arrow implements Icon {
          private boolean descending;
          private int size;
          private int priority;
          public Arrow(boolean descending, int size, int priority) {
              this.descending = descending;
              this.size = size;
              this.priority = priority;
          public void paintIcon(Component c, Graphics g, int x, int y) {
              Color color = c == null ? Color.GRAY : c.getBackground();
              // In a compound sort, make each succesive triangle 20%
              // smaller than the previous one.
              int dx = (int)(size/2*Math.pow(0.8, priority));
              int dy = descending ? dx : -dx;
              // Align icon (roughly) with font baseline.
              y = y + 5*size/6 + (descending ? -dy : 0);
              int shift = descending ? 1 : -1;
              g.translate(x, y);
              // Right diagonal.
              g.setColor(color.darker());
              g.drawLine(dx / 2, dy, 0, 0);
              g.drawLine(dx / 2, dy + shift, 0, shift);
              // Left diagonal.
              g.setColor(color.brighter());
              g.drawLine(dx / 2, dy, dx, 0);
              g.drawLine(dx / 2, dy + shift, dx, shift);
              // Horizontal line.
              if (descending) {
                  g.setColor(color.darker().darker());
              } else {
                  g.setColor(color.brighter().brighter());
              g.drawLine(dx, 0, 0, 0);
              g.setColor(color);
              g.translate(-x, -y);
          public int getIconWidth() {
              return size;
          public int getIconHeight() {
              return size;
      private class SortableHeaderRenderer implements TableCellRenderer {
          private TableCellRenderer tableCellRenderer;
          public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) {
              this.tableCellRenderer = tableCellRenderer;
          public Component getTableCellRendererComponent(JTable table,
                                                         Object value,
                                                         boolean isSelected,
                                                         boolean hasFocus,
                                                         int row,
                                                         int column) {
              Component c = tableCellRenderer.getTableCellRendererComponent(table,
                      value, isSelected, hasFocus, row, column);
              if (c instanceof JLabel) {
                  JLabel l = (JLabel) c;
                  l.setHorizontalTextPosition(JLabel.LEFT);
                  int modelColumn = table.convertColumnIndexToModel(column);
                  l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
              return c;
      private class Directive {
          private int column;
          private int direction;
          public Directive(int column, int direction) {
              this.column = column;
              this.direction = direction;
  //-------------- FIX TABLE'S HEIGHT & COLUMN WIDTH ---------
  public class TableHeight_ColumnWidth {
    private TableSorter sorter;
    private FontMetrics fm;
    private JTable table;
    private int numOfRows = 0, totalTableHeight = 0, totalTableWidth = 0;
     * Constructor --- it needs the model as well the JTable as parameters
     * @param sorter - the model
     * @param table - the JTable created based on the model
    public TableHeight_ColumnWidth(TableSorter sorter, JTable table) {
      this.sorter = sorter;
      this.table = table;
      this.fm = table.getFontMetrics(table.getFont());
      this.numOfRows = table.getRowCount();
     * Calculates the width of each column according to the String it contains
     * @param col = the desired column
     * @param fm = the FontMetrics of this column
     * @return - the width of the single column
    public int determineColumnWidth(TableColumn col, FontMetrics fm) {
      int headerWidth = fm.stringWidth((String)col.getHeaderValue());
      int columnNumber = col.getModelIndex();
      int max = headerWidth;
      int columnWidth = 0;
      String cell = "";
      Integer cell_int = new Integer(0);
      Short cell_short = new Short((short)0);
      for (int i = 0; i != sorter.getRowCount(); i++) {
        Object obj = (Object) sorter.getValueAt(i, columnNumber);
        if (obj instanceof String) {
          cell = (String)sorter.getValueAt(i, columnNumber);
        else if (obj instanceof Integer) {
          cell_int = (Integer)sorter.getValueAt(i, columnNumber);
          cell = String.valueOf(cell_int.intValue());
        else if (obj instanceof Short) {
          cell_short = (Short) sorter.getValueAt(i, columnNumber);
          cell = String.valueOf(cell_short.shortValue());
        columnWidth = fm.stringWidth(cell) + 5;
        if (columnWidth > max) {
          max = columnWidth;
      return max + 5;
     * Calculates the total width of the table according to the width of each
     * column.
     * @return - totalTableWidth
    private int fixColumnWidth () {
      int totalTableWidth = 0;
      TableColumn c = null;
      int cw = 0;
      for (int i = 0; i < table.getColumnCount(); i++) {
        c = table.getColumn(table.getColumnName(i));
        cw = this.determineColumnWidth(c, fm);
        c.setPreferredWidth(cw);
        totalTableWidth = totalTableWidth + cw;
        c.setMinWidth(cw);
      return totalTableWidth;
     * Calculates the height of the table according to the height of each row
     * multiplied by 51 (by default) or by the totalRowsCount.
     * @return - totalTableHeight
    private int fixTableHeight(int maxVisibleRows) {
      int rowHeight = table.getRowHeight();
      //Show maxVisibleRows rows maximum
      if (numOfRows > maxVisibleRows) {
        totalTableHeight = rowHeight * maxVisibleRows;
      else {
        totalTableHeight = rowHeight * numOfRows;
      return totalTableHeight;
     * Sets up the table according to the totalTableWidth and totalTableHeight
    public void fixTableLook(int maxVisibleRows) {
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      totalTableWidth = this.fixColumnWidth();
      totalTableHeight = this.fixTableHeight(maxVisibleRows);
      table.setPreferredScrollableViewportSize(new Dimension(totalTableWidth, totalTableHeight));
}Also, I want some column headers to display their text in two-rows. But by using the HTML technique look at the result in comparison with the previous table I had!
import javax.swing.JFrame;
import java.awt.HeadlessException;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
//--------- TableSorter ----------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;
//---------- Table Height - Column Width
import javax.swing.table.TableColumn;
import java.awt.FontMetrics;
import javax.swing.JTable;
import java.awt.Dimension;
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
public class Test extends JFrame {
  JPanel jPanel1 = new JPanel();
  JPanel jPanel2 = new JPanel();
  JButton jButton1 = new JButton();
  FlowLayout flowLayout1 = new FlowLayout();
  BorderLayout borderLayout1 = new BorderLayout();
  BorderLayout borderLayout2 = new BorderLayout();
  //------------- MY VARIABLES -------------
  String[] columnNames_objectArr = new String[] {
      "Col1",
      "Column 2",
      "Column 3",
      "C4",
      "Col5",
      "Col 6",
  Vector columnNames_vector = new Vector();
  private Vector data_vector = new Vector();
  private Object[][] data_objectArr;
  public TableHeight_ColumnWidth tcw;
  private int totalTableWidth = 0, totalTableHeight = 0;
  private JComboBox jcmbxData = new JComboBox(
      new String[] {"Not Configured", "Switch", "Modem"});
  private int maxVisibleRows = 51;
  TableSorter model;
  private JTable table;
  JScrollPane jScrollPane1;
  public Test(String[] args) throws HeadlessException {
    try {
      jbInit();
      setupGUI();
      launchGUI();
    catch(Exception e) {
      e.printStackTrace();
  private void jbtnClose_actionPerformed(ActionEvent e) {
    dispose();
  private void launchGUI() {
    pack();
    setVisible(true);
    setResizable(false);
  private void setupGUI() {
    columnNames_vector.addElement("<html>Col1</html>");
    columnNames_vector.addElement("<html>Column 2</html>");
    columnNames_vector.addElement("<html>Column 3<br>Second Row</html>");
    columnNames_vector.addElement("<html>C4</html>");
    columnNames_vector.addElement("<html>Col5</html>");
    columnNames_vector.addElement("<html>Col 6</html>");
    Vector row_data1 = new Vector();
    Vector row_data2 = new Vector();
    Vector row_data3 = new Vector();
    Vector row_data4 = new Vector();
    Vector row_data5 = new Vector();
    Vector row_data6 = new Vector();
    row_data1.add("Mary");
    row_data1.add("Campioneato");
    row_data1.add("Snowboarding");
    row_data1.add(new Integer(578987899));
    row_data1.add(new Boolean(false));
    row_data1.add("Not Configured");
    row_data2.add("Alison");
    row_data2.add("Huml");
    row_data2.add("Rowing");
    row_data2.add(new Integer(3));
    row_data2.add(new Boolean(true));
    row_data2.add("Switch");
    row_data3.add("Ka");
    row_data3.add("Walrath");
    row_data3.add("Knitting");
    row_data3.add(new Integer(2));
    row_data3.add(new Boolean(false));
    row_data3.add("Modem");
    row_data4.add("Sharon");
    row_data4.add("Zakhouras");
    row_data4.add("Speed reading");
    row_data4.add(new Integer(20));
    row_data4.add(new Boolean(true));
    row_data4.add("Switch");
    row_data5.add("Philip");
    row_data5.add("Milner");
    row_data5.add("Pool");
    row_data5.add(new Integer(10));
    row_data5.add(new Boolean(false));
    row_data5.add("Not Configured");
    data_vector.add(row_data1);
    data_vector.add(row_data2);
    data_vector.add(row_data3);
    data_vector.add(row_data4);
    data_vector.add(row_data5);
    model = new TableSorter(new SortTableModel(data_vector, columnNames_vector));
    table = new JTable(model);
    tcw = new TableHeight_ColumnWidth(model, table);
    jScrollPane1 = new JScrollPane(table);
    model.setTableHeader(table.getTableHeader());
    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
    //Add a JComboBox as a cellEditor...
    DefaultCellEditor dce = new DefaultCellEditor(jcmbxData);
    table.getColumnModel().getColumn(5).setCellEditor(dce);
    //..... add the IPJPanel as cellEditor.....
    tcw.fixTableLook(maxVisibleRows);
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(borderLayout2);
    jPanel1.setLayout(borderLayout1);
    jPanel2.setLayout(flowLayout1);
    jButton1.setText("Close");
    jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
    jPanel2.add(jButton1, null);
    jButton1.addActionListener(new ActionListener() {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

First of all I found out that when I set the column's header like this:
columnNames_vector.addElement("<html>Column 3<br>Second Row</html>"); //In the setupGUI() methodthe TableHeight_ColumnWidth.determineColumnWidth(TableColumn col, FontMetrics fm) method calculates the column's width by counting <html>, </html>, <br> characters as well. So I added a check to reject these characters and not count them for the column's width.
As for the header's height:
I found that when the first column's header is set to display two-lines, then the height of the rest columns headers is set to display two-lines as well. In other words, the height of the first column's header affects the height of the whole JTableHeader.
I found that the BasicTableHeaderUI.getHeaderHeight() method is called, within which there are these comments:
          // If the header value is empty (== "") in the
          // first column (and this column is set up
          // to use the default renderer) we will
          // return zero from this routine and the header
          // will disappear altogether. Avoiding the calculation
          // of the preferred size is such a performance win for
          // most applications that we will continue to
          // use this cheaper calculation, handling these
          // issues as `edge cases'. Should I override a class and if so which one? I am so confused! If anyone has any idea about how to set the header's height according to the cell's height that is the maximum among all, please let me know.

Similar Messages

  • How to display the column header in two rows?

    Hi Experts,
    I am using ALV_LIST_DISPLAY i neeed to display the column header in two rows.. How can i do that?
    Ex: purchase order i  need to display "purchase" in one row and "order" in second row.
    Thanks in advance,
    Sarath.j

    REPORT zpwtest .
    TYPE-POOLS slis .
    DATA : layout TYPE slis_layout_alv .
    CONSTANTS : c_len TYPE i VALUE 20 .
    TYPES : BEGIN OF ty_t100          ,
              sprsl TYPE t100-sprsl   ,
              arbgb TYPE t100-arbgb   ,
              msgnr TYPE t100-msgnr   ,
              text  TYPE t100-text    ,
              fline TYPE t100-text    ,
            END OF ty_t100            .
    TYPES : BEGIN OF ty_wrd   ,
             text TYPE char20 ,
            END OF ty_wrd     .
    DATA : it_t100     TYPE TABLE OF ty_t100 ,
           it_sentence TYPE TABLE OF ty_wrd  ,
           wa_t100     TYPE ty_t100          ,
           wa_word     TYPE ty_wrd           ,
           v_repid     TYPE syst-repid       ,
           v_tabix     TYPE syst-tabix       .
    DATA : it_fld TYPE slis_t_fieldcat_alv ,
           it_evt TYPE slis_t_event        ,
           wa_fld TYPE slis_fieldcat_alv   ,
           wa_evt TYPE slis_alv_event      .
    INITIALIZATION .
      v_repid = sy-repid .
    START-OF-SELECTION .
    * Get data
      SELECT *
        INTO TABLE it_t100
        FROM t100
       WHERE sprsl = 'EN'
         AND arbgb = '00' .
      LOOP AT it_t100 INTO wa_t100 .
        v_tabix = sy-tabix .
        CLEAR : it_sentence .
        CALL FUNCTION 'RKD_WORD_WRAP'
             EXPORTING
                  textline  = wa_t100-text
                  outputlen = c_len
             TABLES
                  out_lines = it_sentence.
        IF NOT it_sentence IS INITIAL .
          READ TABLE it_sentence INTO wa_word INDEX 1 .
          wa_t100-fline = wa_word-text .
          MODIFY it_t100 FROM wa_t100 INDEX v_tabix .
        ENDIF.
      ENDLOOP.
    * Prepare fieldcatelog
      CLEAR wa_fld .
      wa_fld-fieldname = 'SPRSL' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'SPRSL' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'ARBGB' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'ARBGB' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'MSGNR' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'MSGNR' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'FLINE' .
      wa_fld-inttype      = 'CHAR' .
      wa_fld-outputlen = 20 .
      wa_fld-intlen    = 20.
      wa_fld-seltext_l = 'Text' .
      wa_fld-ddictxt = 'L' .
      APPEND wa_fld TO it_fld .
    * Get event.. we will handle BOFORE and AFTER line output
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           IMPORTING
                et_events = it_evt.
      READ TABLE it_evt INTO wa_evt
      WITH KEY name = slis_ev_after_line_output .
      wa_evt-form = slis_ev_after_line_output .
      MODIFY it_evt FROM wa_evt INDEX sy-tabix .
      READ TABLE it_evt INTO wa_evt
      WITH KEY name = slis_ev_top_of_page .
      wa_evt-form = slis_ev_top_of_page .
      MODIFY it_evt FROM wa_evt INDEX sy-tabix .
      layout-no_colhead = 'X' .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                i_callback_program = v_repid
                it_fieldcat        = it_fld
                is_layout          = layout
                it_events          = it_evt
           TABLES
                t_outtab           = it_t100.
    *       FORM top_of_page                                              *
    FORM top_of_page .
        uline .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line1'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line2'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line3'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
    ENDFORM.
    *       FORM AFTER_LINE_OUTPUT                                        *
    FORM after_line_output   USING rs_lineinfo TYPE slis_lineinfo .
      CLEAR : it_sentence ,
              wa_t100     .
      READ TABLE it_t100 INTO wa_t100 INDEX rs_lineinfo-tabindex .
      CHECK sy-subrc = 0 .
      CALL FUNCTION 'RKD_WORD_WRAP'
           EXPORTING
                textline  = wa_t100-text
                outputlen = c_len
           TABLES
                out_lines = it_sentence.
      DESCRIBE TABLE it_sentence LINES v_tabix .
      CHECK v_tabix > 1 .
      LOOP AT it_sentence INTO wa_word FROM 2 .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               31 sy-vline    ,
               37 sy-vline    ,
               38 wa_word-text ,
               58 sy-vline .
      ENDLOOP.
    ENDFORM .

  • Alv field heading in two rows

    hi all
    In alv report out put  the field heading  is too long.
    So I want to disply the heading in two rows.
    Like ‘ April 2006 prior month personal’,
    Is to be disply like in one row ‘April 2006’.
    And in next row ‘prior month personal’.
    Please send the reply as early as possible to [email protected]

    i think it is not possible like that , u can increase the length of that field in fieldcatalog
    wa_fieldname-outputlen = '100'.
    and in layout u can use
    wa_layout-colwidth_optimize = 'X'.

  • How to make a table control header become two rows?

    Hi, all.
    May I know how to make the static header/label rown in table control on screen become two rows?
    As we know, normally a table control's first row is header, and starting from the second row onwards are it's content or data. So, now I would like to make the hedear/label become first two rows.
    Anyone know about it?
    Thanks in advance.

    Hai Lim,
    Kindly search in SDN.
    "You can't actually have two lines but you can create a title which you may be able to align with the headings to achieve what you want. On the table control tick the 'w/title' box. It then forces you to put an element into a line at the top of the table control."
    Regards,
    Harish

  • Query : In rows, can we split heading in two lines?

    Hi Friends !
    I know, in columns, we can split the heading in two lines.
    In Rows, characteristics " Nomination Header " is there. The output should come like:
    Nomination
    Header
    Awaiting your inputs.
    Thanks
    Rekha

    Hi,
    After entering the text <i>Nomination</i> click on enter button and type <i>Header</i> , in the query designer.
    With rgds,
    Anil Kumar Sharma .P

  • Directory being added two times in JTable rows.(JTable Incorrect add. Rows)

    hi,
    I have a problem, The scenario is that when I click any folder that is in my JTable's row, the table is update by removing all the rows and showing only the contents of my selected folder. If my selected folder contains sub-folders it is some how showing that sub-folder two time and if there are files too that are shown correctly. e.g. If I have a parent folder FG1 and inside that folder I have one more folder FG12 and two .java files then when I click on FG1 my table should show FG12 and two .java files in separate rows, right now it is showing me the contents of FG1 folder but some how FG12 is shown on two rows i.e. first row shows FG12 second row shows FG12 third row shows my .java file and fourth row shows my .java fil. FG12 should be shown only one time. The code is attached. The methods to look are upDateTabel(...) and clearTableData(....), after clearing all my rows then I proceed on adding my data to the Jtable and inserting rows. May be addRow(... method of DefaultTableModel is called two times if it is a directory I don't know why. Please see the code below what I am doing wrong and how to fix it. Any help is appreciated.
    Thanks
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.text.SimpleDateFormat;
    import java.util.*;
    public class SimpleTable extends JPanel {
         /** Formats the date */
         protected SimpleDateFormat           formatter;
    /** two-dimensional array to hold the information for each column */
    protected Object                     data[][];
    /** variable to hold the date and time in a raw form for the directory*/
    protected long                          dateDirectory;
    /** holds the readable form converted date for the directories*/
    protected String                     dirDate;
    /** holds the readable form converted date for the files*/
    protected String                     fileDate;
    /** variable to hold the date and time in a raw form for the file*/
    protected long                          dateFile;
    /** holds the length of the file in bytes */
    protected long                         totalLen;
    /** convert the length to the wrapper class */
    protected Long                         longe;
    /** Vector to hold the sub directories */
    protected Vector                     subDir;
    /** holds the name of the selected directory */
    protected String                    dirNameHold;
    /** converting vector to an Array and store the values in this */
    protected File                     directoryArray[];
    /** hashtable to store the key-value pair */
    protected static Hashtable hashTable = new Hashtable();
    /** refer to the TableModel that is the default*/
    protected DefaultTableModel      model;
    /** stores the path of the selected file */
    protected static String               fullPath;
    /** stores the currently selected file */
    protected static File selectedFilename;
    /** stores the extension of the selected file */
    protected static String           extension;
    /** holds the names of the columns */
    protected final String columnNames[] = {"Name", "Size", "Type", "Modified"};
         * Default constructor
         * @param File the list of files and directories to be shown in the JTable.
    public SimpleTable(File directoryArray[])
              this.setLayout(new BorderLayout());
              this.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
              (SimpleTable.hashTable).clear();
              data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
              formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
              //this shows the data in the JTable i.e. the primary directory stuff.
              for(int k = 0; k < directoryArray.length; k++)
                   if(directoryArray[k].isDirectory())
                        data[k][0] = directoryArray[k].getName();
                        data[k][2] = "File Folder";
                        dateDirectory = directoryArray[k].lastModified();
                        dirDate = formatter.format(new java.util.Date(dateDirectory));
                        data[k][3] = dirDate;
                        (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);                    
                   else if(directoryArray[k].isFile())
                        data[k][0] = directoryArray[k].getName();
                        totalLen = directoryArray[k].length();
                        longe = new Long(totalLen);
                        data[k][1] = longe + " Bytes";
                        dateFile = directoryArray[k].lastModified();
                        fileDate = formatter.format(new java.util.Date(dateFile));
                        data[k][3] = fileDate;
                        (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
    model = new DefaultTableModel();
    model.addTableModelListener( new TableModelListener(){
              public void tableChanged( javax.swing.event.TableModelEvent e )
              final JTable table = new JTable(model);
              table.getTableHeader().setReorderingAllowed(false);
              table.setRowSelectionAllowed(false);
              table.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
              table.setShowHorizontalLines(false);
              table.setShowVerticalLines(false);
              table.addMouseListener(new MouseAdapter()
    public void mouseReleased(MouseEvent e)
    //TBD:- needs to handle the doubleClick of the mouse.
    System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
    if(e.getClickCount() >= 2 &&
    (table.getSelectedColumn() == 0) &&
    ((table.getColumnName(0)).equals(columnNames[0])))
         System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
         upDateTable(table);
    upDateTable(table);
              /** set the columns */
              for(int c = 0; c < columnNames.length; c++)
                   model.addColumn(columnNames[c]);
              /** set the rows */
              for(int r = 0; r < data.length; r++)
                   model.addRow(data[r]);
              //this sets the tool-tip on the headers.
              DefaultTableCellRenderer D_headerRenderer = (DefaultTableCellRenderer ) table.getTableHeader().getDefaultRenderer();
              table.getColumnModel().getColumn(0).setHeaderRenderer(D_headerRenderer );
              ((DefaultTableCellRenderer)D_headerRenderer).setToolTipText("File and Folder in the Current Folder");
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    this.add(scrollPane, BorderLayout.CENTER);
    * Returns the number of columns
    * @return int number of columns
    public int getColumnTotal()
         return columnNames.length;
    * Returns the number of rows
    * @return int number of rows
    public int getRowTotal(Object directoryArray[])
         return directoryArray.length;
    * Update the table according to the selection made if a directory then searches and
    * shows the contents of the directory, if a file fills the appropriate fields.
    * @param JTable table we are working on
    * //TBD: handling of the files.
    private void upDateTable(JTable table)
    if((table.getSelectedColumn() == 0) && ((table.getColumnName(0)).equals(columnNames[0])))
         dirNameHold =(String) table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
                   File argument = findPath(dirNameHold);
                   if(argument.isFile())
                        CMRDialog.fileNameTextField.setText(argument.getName());
                        try
                             fullPath = argument.getCanonicalPath();                          
                             selectedFilename = argument.getCanonicalFile();                          
    CMRDialog.filtersComboBox.removeAllItems();
                             extension = fullPath.substring(fullPath.lastIndexOf('.'));
                             CMRDialog.filtersComboBox.addItem("( " + extension + " )" + " File");
                        catch(IOException e)
                             System.out.println("THE ERROR IS " + e);
                        return;
                   else if(argument.isDirectory())
                        String path = argument.getName();
                             //find the system dependent file separator
                             //String fileSeparator = System.getProperty("file.separator");
                        CMRDialog.driveComboBox.addItem(" " + path);
              subDir = Search.subDirs(argument);
              /**TBD:- needs a method to convert the vector to an array and return the array */
              directoryArray = new File[subDir.size()];
                   int indexCount = 0;
                   /** TBD:- This is inefficient way of converting a vector to an array */               
                   Iterator e = subDir.iterator();               
                   while( e.hasNext() )
                        directoryArray[indexCount] = (File)e.next();
                        indexCount++;
              /** now calls this method and clears the previous data */
              clearTableData(table);     
                   (SimpleTable.hashTable).clear();
                   data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
                   formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
                   data = null;
                   data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
                   for(int k = 0; k < directoryArray.length; k++)
                        if(directoryArray[k].isDirectory())
                             data[k][0] = directoryArray[k].getName();
                             data[k][2] = "File Folder";
                             dateDirectory = directoryArray[k].lastModified();
                             dirDate = formatter.format(new java.util.Date(dateDirectory));
                             data[k][3] = dirDate;
                             (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
                             model.addRow(data[k]);
                             model.fireTableDataChanged();
                        else if(directoryArray[k].isFile())
                             data[k][0] = directoryArray[k].getName();
                             totalLen = directoryArray[k].length();
                             longe = new Long(totalLen);
                             data[k][1] = longe + " Bytes";
                             dateFile = directoryArray[k].lastModified();
                             fileDate = formatter.format(new java.util.Date(dateFile));
                             data[k][3] = fileDate;
                             (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);                    }
                             model.addRow(data[k]);
                             model.fireTableDataChanged();
              table.revalidate();
              table.validate();               
    * Searches the Hashtable and returns the path of the folder or the value.
    * @param String name of the directory or file.
    * @return File     full-path of the selected file or directory.
    public File findPath(String value)
         return (File)((SimpleTable.hashTable).get(value));
    * This clears the previous data in the JTable and removes the rows.
    * @param     JTable table we are updating.
    public void clearTableData(JTable table)
         for(int row = table.getRowCount() - 1; row >= 0; --row)
                   model.removeRow(row);
              model.fireTableStructureChanged();

    java gurus any idea how ti fix this problem.
    thanks

  • JTable - One Column Heading for Two Columns

    Can you adjust the default JTable to have one column heading for two columns of data? Is there a simple span command? I've looked at the api for JTable and JTableHeader and didn't see anything, is there something I'm missing? Any help would be appreciated.

    What i am trying to accomplish is have column 'E' span 2 columns.
    This is my code thus far, however it give the error from my pryor message. I am pretty sure it is because I'm using and Object[][] and a String[] instead of Vectors. What corrections do I need to make in order for my goal of:
    [ A ][ B ][ C ][ D ][ E  ][ F ][ G ]
    [ 1 ][ 2 ][ 3 ][ 4 ][5][6][ 7 ][ 8 ]
    Object[][] data = new Object[ROWS][COLUMNS];
    String[] columnNames = {"A","B","C","D","E","E","F","G"};
    table = new JTable(data, columnNames);
    table.setBackground(Color.white);
    table.addKeyListener(this);
    DefaultTableCellRenderer d = new DefaultTableCellRenderer();
    d.setHorizontalAlignment(JLabel.CENTER);
    table.setDefaultRenderer(table.getColumnClass(0),d);
    for (int i = 0; i < table.getColumnCount(); i++){
    TableColumn aColumn = header.getColumnModel().getColumn(i);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null) {
    renderer = new DefaultTableCellRenderer(){
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
    JTableHeader header = table.getTableHeader();
    if (header != null) {
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    setHorizontalAlignment(JLabel.CENTER);
    setText((value == null) ? "" : value.toString());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    return this;
    aColumn.setHeaderRenderer(renderer);

  • How do i change the cursor on a jtable header when clicked for sorting?

    here is my question, how do i change the cursor on a jtable header when I click the header for sorting?
    I think it is suppose to be in the fragment of code where the header listener is implemented for sorting, but I'm not quite sure what is the exact component that holds everything so that i can change the cursor...
    below is what I've tried, but it doesn't seem to work... thank you
    public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new
    MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    TableColumnModel columnModel =
    tableView.getColumnModel();
    int viewColumn =
    columnModel.getColumnIndexAtX(e.getX());
    int column =
    tableView.convertColumnIndexToModel
    (viewColumn);
    System.out.println("column = "+column);
    if (e.getClickCount() == 1 && column != -1) {
    System.out.println("Sorting ...");
    Cursor oldCursor =
    tableView.getRootPane().getCursor();
    System.out.println("oldCursor.getType()
    = "+oldCursor.getType());
    if (oldCursor.getType() !=
    Cursor.WAIT_CURSOR){
    JComponent parentPane =
    tableView.getRootPane();
    parentPane.getContentPane().setCursor
    (new Cursor(Cursor.WAIT_CURSOR));
    parentPane.setCursor(new Cursor
    (Cursor.WAIT_CURSOR));
    Cursor newCursor =
    parentPane.getCursor();
    System.out.println("newCursor.getType
    () = "+newCursor.getType());
    int shiftPressed = e.getModifiers(
    &InputEvent.SHIFT_MASK;
    boolean ascending = (shiftPressed == 0);
    //System.out.println("tableView.getRootPane()
    is "+tableView.getRootPane().getRootPane());
    sorter.sortByColumn(column, ascending);
    tableView.getRootPane().setCursor(new Cursor
    (Cursor.DEFAULT_CURSOR));
    //System.out.println("Done sorting");
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
    }

    Hi,
    Try setting the cursor for the table header.
    table.getHeader().setCursor(Wait_Cursor);
    Bala.

  • How to change JTable column header text

    How do you set the text in the JTable column headers? I know you can create a JTable specifying the text in an array:
    <li>JTable(Object[][] rowData, Object[] columnNames)
    But if you create the JTable specifying a TableModel,
    <li>JTable(TableModel dm)
    the header text defaults to "A", "B", "C", etc. I cannot figure out how to access the text in the header names so it can be changed to something useful. I know how to get the JTableHeader for the table, but it does not seem to have methods for actually setting header values.

    I'm sure that model allows you to specify header values so you don't have to do so manually. I would be very surprised if it didn't override the default getColumnName() method to provide a reasonable names.She wasn't writing the class, but [url http://forums.oracle.com/forums/thread.jspa?messageID=9200751#9200751]outlining a design for me to implement. And, based on a previous comment I had made, I think she assumed I wanted the new design to look as much like the old as possible. There were no headers in the original design, which wasn't even a table.
    Anyway, this works:
        final static String statisticsColumnNames[] = {
         "Type", "Count",
         "Red QE", "Green QE", "Blue QE", "Average QE",
         "Distance"
         qErrors = new QEBeanTableModel();
         JTable errorTable = new JTable(qErrors);
         TableColumnModel tcm = errorTable.getColumnModel();
         for (int col = 0; col < statisticsColumnNames.length; col++)
             tcm.getColumn(col).setHeaderValue(statisticsColumnNames[col]);
    It looks like setHeaderValue() on the TableColumn is what I was looking for.Again, only used if you are dynamically changing the values at run time or you don't like the defaults provided by the Bean-aware model.I coded the above before I read your last post. The QEBeanTableModel is extremely specific to my program. I.e. I cannot imagine it being used anywhere else. Would it still be better to implement a getColumnName() within the table model? Looking at your [url http://www.camick.com/java/source/RowTableModel.java]RowTableModel.java source, I can see that it would not be difficult to do so.
    Just decided to add the getColumnName() method. This whole sub-project is based on implementing a clean modern design (and learning about Java Beans). You've clearly stated twice that the method I have implemented is for dynamic header values only, which has already answered what I asked last paragraph.

  • Line of text in two rows in a check box

    Greets
    Ive been working in a poll, and i use a check box in some part, but de question its to long to put it in
    i have the same problem with the text box, but with the command &#13; it can be possible to put a long question in two rows, but that command line doesnt work with check boxes
    there are any form to make a long question of one row, into a two row question in check box component??

    There is a multiline button example you can adapt for checkboxes on my blog.
    Alex Harui
    Flex SDK Team
    Adobe System, Inc.
    http://blogs.adobe.com/aharui

  • Is it possible to have two rows of text fields per entry in a tabular form?

    Hi,
    I'm constructing a tabular form with several text fields for each entry, and I have just been advised we need twice as many text fields now as the requirements have changed.
    Anyway I am running out of real estate on the page without having to use horizontal scroll bars, and am wondering if it is possible to arrange the text fields into two rows in the tabular form for data entry. I have successfully done this for display as text fields, but not sure if it can be done in this instance.
    Any help would be greatly appreciated.
    Application Express 4.1.1.00.23
    Greg
    Edited by: Snowman on Nov 30, 2012 12:02 PM

    Snowman wrote:
    Hi,
    I'm constructing a tabular form with several text fields for each entry, and I have just been advised we need twice as many text fields now as the requirements have changed.In the first place I'd strongly recommend not using tabular forms: +{thread:id=850889}+.
    Anyway I am running out of real estate on the page without having to use horizontal scroll bars, and am wondering if it is possible to arrange the text fields into two rows in the tabular form for data entry. I have successfully done this for display as text fields, but not sure if it can be done in this instance.If you must, create a custom named column template and base the tabular form report on this: {message:id=10399762}

  • Including a JDialog or JFrame between two rows in a JTable

    Hello,
    Is it possible to include a JFrame or JDialog between two rows in a JTable?
    I would like two have a JFrame or JDialog which shift all the rows below the row that I want in order to include a JFrame between them.
    Thank in advance

    [http://forums.sun.com/thread.jspa?threadID=5331582]

  • Interactive report – column heading in multiple rows

    I am using interactive report. My question to the expert/guru&rsquo;s is: - How do I change column heading into multiple row with text wrap.
    For example:- My column heading is
    Is Employee Trained ? -------&gt; (single row display)
    I want to make it display like
    Is Employee
    Trained ? ------&gt; (Multi row display)
    Sagar

    Hi,
    What you could do is, disable the download csv function from IR (Interactive Report Attributes--> Search Bar-- Uncheck Download) and in the region header create a link and redirect it to another page which will have the csv report output.
    e.g. <a href="#"  onclick="javascript:redirect('f?p=&APP_ID.:3:&SESSION.::&DEBUG.:3::');"" >Download Report </a>
    Here I am redirecting the link to Page 3. On Page 3 create a sql report with the same query and make report template to csv. Thanks,
    Manish

  • Can I use photoshop text styles and photoshop actions with creative cloud photography?

    I'm really confused by this subscription pricing. If I purchase the $9.99/month, do I get the full desktop app of Photoshop and Lightroom? But I see on this page Products they list something called Photoshop CC that costs twice as much. How is that different from the Creative Cloud Photography?
    My main question is whether I can use photoshop text styles and photoshop actions with Creative Cloud Photography, since I just purchased a bundle that includes these and I want to be able to use them. But I'd also like to understand what comes with all of the various products and how they are different.
    My other question is how is Lightroom different from Photoshop? I have a sense of what you can do in Photoshop but I don't know much about Lightroom at all.
    One more question: the free trial -- is it limited in any way besides the time length? If I do that, will I get a clear idea of all that I will be able to do once I subscribe, or are the functions limited in the trial?
    I tried to just send an email to Adobe to ask these questions but apparently they are not interested in responding to emails from people who are not yet paying customers, so I was directed here. Thanks very much for your help!

    I always like to trot this bit about Bridge once in a while or in the voice of the "Two Bobs" from Office Space,
    "Can you tell us exactly what it is you do around here?"
    What Adobe Bridge does:
    Bridge is the coordinating hub of the Creative Suite. Synchronizing color management settings for all suite programs is done from Bridge, and can only be done from Bridge, to take one important use.
    Bridge displays actual thumbnails of many more file types than Finder or Explorer. It also allows instant play of sound or video files more readily than the native OS file managers.
    Bridge allows direct access to file metadata, to embed copyright information  and keywords where appropriate (e.g., for corporate logo vector and raster files). It also displays the fonts used in an InDesign file, the swatches in an INDD or AI and the output plates (including spot color plates) they use.
    When managing the assets for a design project, Bridge allows quick and simple sorting, rating and custom labeling (with color flash indications) of assets. I can rate images according to whether they are rejects, possibles, for review by client, or approved. The filters built into Bridge allow instant isolation of only the approved images or designs in a folder, only the rejects (for deletion) or only files with certain ratings, no matter how many files it contains. It recognizes aspect ratios, so if I only need a landscape or a 16:9 image in a folder of hundreds of images, I turn off the aspect ratios I don't need.
    Once filtered, the remaining visible files can be selected and copied, moved, or deleted without affecting the rest of the contents of a folder.
    Collections are a massively useful feature. One of my clients is a performing arts center, and in a season we turn out dozens of ads, flyers, brochures, web banners, playbills, billboards and other collateral using the same assets over and over. These assets are organized by artist and/or show on disk, but I set up each season's repeating assets as a Collection in Bridge, so that I just have to open the collection and drag and drop these assets into new INDD, AI, PSD, HTML (in Dreamweaver), FLA or AE projects without having to navigate from folder to folder picking up individual files.
    Bridge's Favorites is another place I stack frequently-accessed folders, such as stock photography, backgrounds, and top-level folders for active projects.
    Assets can be divided into subfolders, but a quick toggle of "Show items from subfolders" exposes all of the assets in a single view while maintaining their organization. I will typically keep AIs, PSDs, EPSs, stock photography and client images in separate subfolders within a project. When I'm ready to start pulling assets into an InDesign layout, I toggle this on and simply drag what I need into the layout.
    Bridge comes with Adobe Camera Raw built in, which is many times faster than using Photoshop to adjust jpegs or tiffs for things like tonal range, white balance, cropping, spotting and sharpening, and is non-destructive.
    One tremendously useful Bridge function for InDesign CS5+ users is the "Show linked files" feature, which opens all the linked files in a layout into a single view, regardless of where they are physically located. I often use this when doing alternative layouts from a client-approved mockup for a campaign, to be certain the same assets are used in each piece, or when creating a motion graphic or interactive piece for the campaign in After Effects or Flash.
    The batch and image processing scripts built into Bridge automate things like creating web-ready small jpegs from multiple images, renaming large numbers of files in place or by copying to an alternative location, creating sets of PSD, png, jpeg or other file types from an assortment of image files, and so on.
    Bridge is so much a part of my daily workflow that on my main workstation I have one monitor dedicated to it almost 100%. Bridge just sits open 24/7, ready for use. I would run at half speed without it, no question.

  • How to add  ComboBox in Jtable Header

    Hello everyone,
    I want to add a Combox box in JTable Header .Basically it works as central access to whole table e.g. by selecting delete row in combo box then it should delete the current selected row.If somebody has any idea please share it.
    Thanks in advance.

    The individual headers are not Swing components and therefore do not respond to mouse events in the same way as Swing components. Why don't you just have a popup menu that is positioned over the currently selected row? If you want to apply an action to all selected rows then have a set of buttons placed above the table header.

Maybe you are looking for

  • Can multiple remote desktops control the same machine at the same time?

    Can anyone please tell me if this set up possible: mac mini running XP app iMac logged into to control that app ibook logged in to control that app of course, only one person actually moving the mouse / using the keyboard at one time. Miklos.

  • How to use URL parameters in Flex?

    Hello Everyone, I wanted to know how can the parameters passed in a URL be used in our Flex application. I searched in the forum and tried these links: http://forums.adobe.com/message/217950#217950 http://www.danvega.org/blog/index.cfm/2009/2/5/Flex-

  • Need help in date conversion(it's Urgent)

    I am reading data from the text file... and inserting that data into the oracle table(using bpel process) I have following problem with the date field. In the XSD file if i specify the date format as nxsd:dateFormat="ddMMyyyy" and when i pass null va

  • CiscoWorks LMS 4.0.1 High Memory Utilization on Windows 2K8 R2

    Hi, What causes LMS 4.1 to have high memory utilization?

  • Dashboard URL not opening

    Hi, I am trying to access the dashboard URL using http://<mc name>:9704/analytics/saw.dll?Dashboard It shows login page. I entered default Administrator user and password as SADMIN. Then click go. It show "Logging in. Please wait" and it is not going