Java Code Examples for javax.swing.table.JTableHeader

The following examples show how to use javax.swing.table.JTableHeader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: TableSorter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
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 += e.isShiftDown() ? -1 : 1;
        status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setSortingStatus(column, status);
        if(issueTable != null) {
            issueTable.sortOrderChanged();
        }
    }
}
 
Example 2
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    final MouseAdapter listMouseListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            final TableColumnModel columnModel = tableView.getColumnModel();
            final int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            final int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                //System.out.println("Sorting ...");
                final int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK;
                final boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    final JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example 3
protected void initTaxonSetsTable(AbstractTableModel tableModel, final String[] columnToolTips) {
    taxonSetsTable = new JTable(tableModel) {
        //Implement table header tool tips.
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                public String getToolTipText(MouseEvent e) {
                    Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };
    taxonSetsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    taxonSetsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            taxonSetsTableSelectionChanged();
        }
    });
    taxonSetsTable.doLayout();
}
 
Example 4
Source Project: jdk8u-jdk   Source File: TableSorter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example 5
Source Project: netbeans   Source File: ETableColumn.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Forces the table to resize given column.
 */
private void resize(int newWidth, JTable table) {
    int oldWidth = getWidth();
    JTableHeader header = table.getTableHeader();
    if (header == null) {
        return;
    }
    header.setResizingColumn(this);
    final int oldMin = getMinWidth();
    final int oldMax = getMaxWidth();
    setMinWidth(newWidth);
    setMaxWidth(newWidth);
    setWidth(newWidth);
    // The trick is to restore the original values
    // after the table has be layouted. During layout this column
    // has fixed width (by setting min==max==preffered)
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            setMinWidth(oldMin);
            setMaxWidth(oldMax);
        }
    });
    Container container;
    if ((header.getParent() == null) ||
            ((container = header.getParent().getParent()) == null) ||
            !(container instanceof JScrollPane)) {
        header.setResizingColumn(null);
        return;
    }
    
    if (!container.getComponentOrientation().isLeftToRight() &&
            ! header.getComponentOrientation().isLeftToRight()) {
        if (table != null) {
            JViewport viewport = ((JScrollPane)container).getViewport();
            int viewportWidth = viewport.getWidth();
            int diff = newWidth - oldWidth;
            int newHeaderWidth = table.getWidth() + diff;
            
            /* Resize a table */
            Dimension tableSize = table.getSize();
            tableSize.width += diff;
            table.setSize(tableSize);
            
            /* If this table is in AUTO_RESIZE_OFF mode and
             * has a horizontal scrollbar, we need to update
             * a view's position.
             */
            if ((newHeaderWidth >= viewportWidth) &&
                    (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                Point p = viewport.getViewPosition();
                p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                viewport.setViewPosition(p);
            }
        }
    }
    header.setResizingColumn(null);
}
 
Example 6
Source Project: ghidra   Source File: MemoryMapProvider1Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSortNames() {
	JTableHeader header = table.getTableHeader();
	Rectangle rect = header.getHeaderRect(MemoryMapModel.NAME);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	String[] names = new String[blocks.length];
	for (int i = 0; i < names.length; i++) {
		names[i] = blocks[i].getName();
	}
	// sort ascending
	Arrays.sort(names);
	for (int i = names.length - 1; i >= 0; i--) {
		assertEquals(names[i], model.getValueAt(i, MemoryMapModel.NAME));
	}
}
 
Example 7
/**
 * This method ensures that the correct tool tip for the current column is delivered.
 */
@Override
protected JTableHeader createDefaultTableHeader() {
	JTableHeader header = new JTableHeader(columnModel) {

		private static final long serialVersionUID = 1L;

		@Override
		public String getToolTipText(MouseEvent e) {
			java.awt.Point p = e.getPoint();
			int index = columnModel.getColumnIndexAtX(p.x);
			int realColumnIndex = convertColumnIndexToModel(index);
			return DataViewerTable.this.getHeaderToolTipText(realColumnIndex);
		}
	};
	header.putClientProperty(RapidLookTools.PROPERTY_TABLE_HEADER_BACKGROUND, Colors.WHITE);
	return header;
}
 
Example 8
Source Project: ghidra   Source File: MemoryMapProvider1Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSortBlockType() throws Exception {

	// add a bit overlay block, live block, and an unitialized block
	int transactionID = program.startTransaction("test");
	memory.createBitMappedBlock(".Bit", getAddr(0), getAddr(0x01001000), 0x100, false);
	memory.createUninitializedBlock(".Uninit", getAddr(0x3000), 0x200, false);
	program.endTransaction(transactionID, true);

	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.BLOCK_TYPE);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);
	MemoryBlock[] blocks = memory.getBlocks();

	String[] typeNames = new String[blocks.length];
	for (int i = 0; i < typeNames.length; i++) {
		typeNames[i] = blocks[i].getType().toString();
	}
	Arrays.sort(typeNames);

	for (int i = 0; i < typeNames.length; i++) {
		assertEquals(typeNames[i], model.getValueAt(i, MemoryMapModel.BLOCK_TYPE));
	}

}
 
Example 9
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
@Override public void mouseClicked(MouseEvent e) {
  JTableHeader header = (JTableHeader) e.getComponent();
  JTable tbl = header.getTable();
  TableColumnModel columnModel = tbl.getColumnModel();
  TableModel m = tbl.getModel();
  int vci = columnModel.getColumnIndexAtX(e.getX());
  int mci = tbl.convertColumnIndexToModel(vci);
  if (mci == targetColumnIndex && m.getRowCount() > 0) {
    TableColumn column = columnModel.getColumn(vci);
    boolean b = column.getHeaderValue() == Status.DESELECTED;
    for (int i = 0; i < m.getRowCount(); i++) {
      m.setValueAt(b, i, mci);
    }
    column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED);
    // header.repaint();
  }
}
 
Example 10
Source Project: TencentKona-8   Source File: TableSorter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example 11
/**
 * Handle a mouse press event - if the user is NOT resizing a column and NOT dragging a column
 * then give visual feedback that the column header has been pressed.
 *
 * @param e  the mouse event.
 */
public void mousePressed(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if (header.getResizingColumn() == null) {  // resizing takes precedence over sorting
        if (header.getDraggedDistance() < 1) {   // dragging also takes precedence over sorting
            final int columnIndex = header.columnAtPoint(e.getPoint());
            final int modelColumnIndex 
                = header.getTable().convertColumnIndexToModel(columnIndex);
            if (this.model.isSortable(modelColumnIndex)) {
                this.sortColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex);
                this.renderer.setPressedColumn(this.sortColumnIndex);
                header.repaint();
                if (header.getTable().isEditing()) {
                    header.getTable().getCellEditor().stopCellEditing();
                }
            }
            else {
                this.sortColumnIndex = -1;
            }
        }
    }

}
 
Example 12
public static void initializeTable(JTable table)
{
	table.setAutoCreateColumnsFromModel(false);
	JTableHeader header = table.getTableHeader();
	TableColumnModel columns = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = header.getDefaultRenderer();
	columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false));
	columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true));
	TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false);
	remainCol.setCellRenderer(new BoldNumberRenderer());
	columns.addColumn(remainCol);
	columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false));
	table.setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
	table.setColumnModel(columns);
	table.setFocusable(false);
	header.setReorderingAllowed(false);
	header.setResizingAllowed(false);
}
 
Example 13
Source Project: netbeans   Source File: TimelineHeaderRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    boolean timelineColumn = column == table.convertColumnIndexToModel(col);
    setVisible(timelineColumn);
    
    Component c = impl.getTableCellRendererComponent(table, timelineColumn ?
                  " " : value, isSelected, hasFocus, row, col); // NOI18N
    if (timelineColumn) {
        if (getParent() == null && c instanceof Container) ((Container)c).add(this);

        JTableHeader header = table.getTableHeader();
        if (painter == null) initStaticUI(c, header);
        
        TableColumn _column = header.getColumnModel().getColumn(col);
        
        setSize(_column.getWidth(), header.getSize().height);
    }
    
    return c;
}
 
Example 14
Source Project: java-swing-tips   Source File: TableSorter.java    License: MIT License 6 votes vote down vote up
@Override public void mouseClicked(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  TableColumnModel columnModel = h.getColumnModel();
  int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  // ArrayIndexOutOfBoundsException: -1
  if (viewColumn < 0) {
    return;
  }
  int column = columnModel.getColumn(viewColumn).getModelIndex();
  if (column != -1) {
    int status = getSortingStatus(column) + (e.isShiftDown() ? -1 : 1);
    if (!e.isControlDown()) {
      cancelSorting();
    }
    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
    // int d = e.isShiftDown() ? -1 : 1;
    // status = status + d;
    status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
    setSortingStatus(column, status);
  }
}
 
Example 15
Source Project: jplag   Source File: TableSorter.java    License: GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example 16
Source Project: SimpleERP   Source File: QueryDailyIncome.java    License: Apache License 2.0 6 votes vote down vote up
public static void FitTableColumns(JTable myTable){
	  JTableHeader header = myTable.getTableHeader();
	     int rowCount = myTable.getRowCount();
	     Enumeration columns = myTable.getColumnModel().getColumns();
	     while(columns.hasMoreElements()){
	         TableColumn column = (TableColumn)columns.nextElement();
	         int col = header.getColumnModel().getColumnIndex(column.getIdentifier());
	         int width = (int)myTable.getTableHeader().getDefaultRenderer()
	                 .getTableCellRendererComponent(myTable, column.getIdentifier()
	                         , false, false, -1, col).getPreferredSize().getWidth();
	         for(int row = 0; row<rowCount; row++){
	             int preferedWidth = (int)myTable.getCellRenderer(row, col).getTableCellRendererComponent(myTable,
	               myTable.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
	             width = Math.max(width, preferedWidth);
	         }
	         header.setResizingColumn(column); // ���к���Ҫ
	         column.setWidth(width+myTable.getIntercellSpacing().width);
	     }
}
 
Example 17
Source Project: hottub   Source File: TableSorter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example 18
Source Project: openjdk-jdk8u   Source File: TableSorter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example 19
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void show(Component c, int x, int y) {
  if (c instanceof JTableHeader) {
    JTableHeader header = (JTableHeader) c;
    header.setDraggedColumn(null); // bookmark_1
    // if (header.getDraggedColumn() != null) remain dirty area >>>
    header.repaint();
    header.getTable().repaint();
    // <<<
    index = header.columnAtPoint(new Point(x, y));
    super.show(c, x, y);
  }
}
 
Example 20
/**
 * Maps {@code JTableHeader.getDraggedColumn()} through queue
 */
public TableColumn getDraggedColumn() {
    return (runMapping(new MapAction<TableColumn>("getDraggedColumn") {
        @Override
        public TableColumn map() {
            return ((JTableHeader) getSource()).getDraggedColumn();
        }
    }));
}
 
Example 21
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
public Dimension getSize(JTableHeader header) {
  TableCellRenderer r = header.getDefaultRenderer();
  Component c = r.getTableCellRendererComponent(header.getTable(), getHeaderValue(), false, false, -1, -1);
  int width = 0;
  for (Object obj: list) {
    if (obj instanceof TableColumn) {
      TableColumn tc = (TableColumn) obj;
      width += tc.getWidth();
    } else {
      width += ((ColumnGroup) obj).getSize(header).width;
    }
  }
  return new Dimension(width, c.getPreferredSize().height);
}
 
Example 22
Source Project: netbeans   Source File: OptionsAction.java    License: Apache License 2.0 5 votes vote down vote up
public void mouseClicked (MouseEvent evt) {
    Component c = evt.getComponent ();
    if (c instanceof JTableHeader) {
        JTableHeader h = (JTableHeader)c;
        
        // show/hide additional properties
        if (1 == h.columnAtPoint (evt.getPoint ())) {
            refreshColumns (true);
        }
    }
}
 
Example 23
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());

  String[] columnNames = {"Default", "GlyphVector", "JTextArea"};
  Object[][] data = {
    {STR0, STR1, STR2}, {STR0, STR1, STR2},
    {STR3, STR3, STR3}, {STR3, STR3, STR3}
  };
  TableModel model = new DefaultTableModel(data, columnNames) {
    @Override public Class<?> getColumnClass(int column) {
      return getValueAt(0, column).getClass();
    }
  };
  JTable table = new JTable(model) {
    @Override public void updateUI() {
      getColumnModel().getColumn(1).setCellRenderer(null);
      getColumnModel().getColumn(2).setCellRenderer(null);
      super.updateUI();
      setRowSelectionAllowed(true);
      setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
      setRowHeight(50);
      getColumnModel().getColumn(1).setCellRenderer(new TestRenderer());
      getColumnModel().getColumn(2).setCellRenderer(new TextAreaCellRenderer());
    }
  };

  JTableHeader tableHeader = table.getTableHeader();
  tableHeader.setReorderingAllowed(false);

  add(new JScrollPane(table));
  setPreferredSize(new Dimension(320, 240));
}
 
Example 24
/**
 * Maps {@code JTableHeader.setUI(TableHeaderUI)} through queue
 */
public void setUI(final TableHeaderUI tableHeaderUI) {
    runMapping(new MapVoidAction("setUI") {
        @Override
        public void map() {
            ((JTableHeader) getSource()).setUI(tableHeaderUI);
        }
    });
}
 
Example 25
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void show(Component c, int x, int y) {
  if (c instanceof JTableHeader) {
    JTableHeader header = (JTableHeader) c;
    JTable table = header.getTable();
    header.setDraggedColumn(null);
    header.repaint();
    table.repaint();
    int i = table.convertColumnIndexToModel(header.columnAtPoint(new Point(x, y)));
    if (i >= 0) {
      actions.forEach(a -> a.setIndex(i));
      super.show(c, x, y);
    }
  }
}
 
Example 26
/**
 * Maps {@code JTableHeader.columnMarginChanged(ChangeEvent)} through queue
 */
public void columnMarginChanged(final ChangeEvent changeEvent) {
    runMapping(new MapVoidAction("columnMarginChanged") {
        @Override
        public void map() {
            ((JTableHeader) getSource()).columnMarginChanged(changeEvent);
        }
    });
}
 
Example 27
Source Project: openjdk-8-source   Source File: bug6889007.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(20);

    final JFrame frame = new JFrame();
    frame.setUndecorated(true);

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JTableHeader th = new JTableHeader();
            th.setColumnModel(new JTable(20, 5).getColumnModel());

            th.setUI(new MyTableHeaderUI());

            frame.add(th);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    Point point = frame.getLocationOnScreen();
    int shift = 10;
    int x = point.x;
    int y = point.y + frame.getHeight()/2;
    for(int i = -shift; i < frame.getWidth() + 2*shift; i++) {
        robot.mouseMove(x++, y);
    }
    toolkit.realSync();
    // 9 is a magic test number
    if (MyTableHeaderUI.getTestValue() != 9) {
        throw new RuntimeException("Unexpected test number "
                + MyTableHeaderUI.getTestValue());
    }
    System.out.println("ok");
}
 
Example 28
void setModel(TableModel tableModel) {
    table.setModel(tableModel);
    if (table.getColumnCount() > 0) {
        final JTableHeader tableHeader = table.getTableHeader();
        final int margin = tableHeader.getColumnModel().getColumnMargin();
        final TableCellRenderer renderer = tableHeader.getDefaultRenderer();
        final Enumeration<TableColumn> columns = table.getColumnModel().getColumns();
        while (columns.hasMoreElements()) {
            TableColumn tableColumn = columns.nextElement();
            final int width = getColumnMinWith(tableColumn, renderer, margin);
            tableColumn.setMinWidth(width);
        }
    }
}
 
Example 29
Source Project: netbeans   Source File: DataViewBuilders.java    License: Apache License 2.0 5 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JComboBox.class.getName())) {
        return new JComboBoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JList.class.getName())) {
        return new JListBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JTree.class.getName())) {
        return new JTreeBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JTable.class.getName())) {
        return new JTableBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JTableHeader.class.getName())) {
        return new JTableHeaderBuilder(instance, heap);
    }
    return null;
}
 
Example 30
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void tableChanged(TableModelEvent e) {
  if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == targetColumnIndex) {
    int vci = table.convertColumnIndexToView(targetColumnIndex);
    TableColumn column = table.getColumnModel().getColumn(vci);
    Object status = column.getHeaderValue();
    TableModel m = table.getModel();
    if (m instanceof DefaultTableModel && fireUpdateEvent((DefaultTableModel) m, column, status)) {
      JTableHeader h = table.getTableHeader();
      h.repaint(h.getHeaderRect(vci));
    }
  }
}