javax.swing.table.JTableHeader Java Examples

The following examples show how to use javax.swing.table.JTableHeader. 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 File: TableSorter.java    From hottub with 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 #2
Source File: TableSorter.java    From jplag with 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 #3
Source File: QueryDailyIncome.java    From SimpleERP with 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 #4
Source File: TableSorter.java    From netbeans with 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 #5
Source File: TableSorter.java    From java-swing-tips with 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 #6
Source File: TimelineHeaderRenderer.java    From netbeans with 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 #7
Source File: SkillPointTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 #8
Source File: SortableTableHeaderListener.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #9
Source File: TableSorter.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #10
Source File: TableSorter.java    From jdk8u-jdk with 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
Source File: TableSorter.java    From TencentKona-8 with 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 #12
Source File: DataViewerTable.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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 #13
Source File: MemoryMapProvider1Test.java    From ghidra with 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 #14
Source File: MemoryMapProvider1Test.java    From ghidra with 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 #15
Source File: TableSorter.java    From openjdk-jdk8u with 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 #16
Source File: ETableColumn.java    From netbeans with 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 #17
Source File: MainPanel.java    From java-swing-tips with 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 #18
Source File: TaxonSetPanel.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 #19
Source File: DarculaTableHeaderUI.java    From Darcula with Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g2, JComponent c) {
  final Graphics2D g = (Graphics2D)g2;
  final GraphicsConfig config = new GraphicsConfig(g);
  final Color bg = c.getBackground();
  g.setPaint(new GradientPaint(0, 0, ColorUtil.shift(bg, 1.4), 0, c.getHeight(), ColorUtil.shift(bg, 0.9)));
  final int h = c.getHeight();
  final int w = c.getWidth();
  g.fillRect(0,0, w, h);
  g.setPaint(ColorUtil.shift(bg, 0.75));
  g.drawLine(0, h-1, w, h-1);
  g.drawLine(w-1, 0, w-1, h-1);

  final Enumeration<TableColumn> columns = ((JTableHeader)c).getColumnModel().getColumns();

  final Color lineColor = ColorUtil.shift(bg, 0.7);
  final Color shadow = Gray._255.withAlpha(30);
  int offset = 0;
  while (columns.hasMoreElements()) {
    final TableColumn column = columns.nextElement();
    if (columns.hasMoreElements() && column.getWidth() > 0) {
      offset += column.getWidth();
      g.setColor(lineColor);
      g.drawLine(offset-1, 1, offset-1, h-3);
      g.setColor(shadow);
      g.drawLine(offset, 1, offset, h-3);
    }
  }

  config.restore();

  super.paint(g, c);
}
 
Example #20
Source File: JTableHeaderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTableHeader.columnSelectionChanged(ListSelectionEvent)}
 * through queue
 */
public void columnSelectionChanged(final ListSelectionEvent listSelectionEvent) {
    runMapping(new MapVoidAction("columnSelectionChanged") {
        @Override
        public void map() {
            ((JTableHeader) getSource()).columnSelectionChanged(listSelectionEvent);
        }
    });
}
 
Example #21
Source File: MainPanel.java    From java-swing-tips with 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);
    header.repaint();
    header.getTable().repaint();
    updateMenuItems(header.getColumnModel());
    super.show(c, x, y);
  }
}
 
Example #22
Source File: bug6889007.java    From jdk8u-jdk with 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 #23
Source File: JTableHeaderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTableHeader.getReorderingAllowed()} through queue
 */
public boolean getReorderingAllowed() {
    return (runMapping(new MapBooleanAction("getReorderingAllowed") {
        @Override
        public boolean map() {
            return ((JTableHeader) getSource()).getReorderingAllowed();
        }
    }));
}
 
Example #24
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortBlockTypeDescending() 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);

	// descending
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();

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

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

}
 
Example #25
Source File: MainPanel.java    From java-swing-tips with 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 #26
Source File: SubstanceTableHeaderUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean hasLeadingVerticalGridLine(JTableHeader tableHeader, Rectangle cellRect,
        int column) {
    if (column != 0) {
        return false;
    }
    Container parent = tableHeader.getParent();
    if (parent instanceof JViewport) {
        Container grand = parent.getParent();
        if (grand instanceof JScrollPane) {
            return (((JScrollPane) grand).getRowHeader() != null);
        }
    }
    return false;
}
 
Example #27
Source File: FreeColTableHeaderUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
    super.installUI(c);

    JTableHeader j = (JTableHeader) c;
    j.setOpaque(false);

    DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) j.getDefaultRenderer();
    dtcr.setOpaque(false);
}
 
Example #28
Source File: TableSorter.java    From java-swing-tips with MIT License 5 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) {
    JTable t = h.getTable();
    int keyCol = 0;
    // List<?> list = saveSelectedRow(t, keyCol);
    List<Object> list = new ArrayList<>();
    int[] ilist = t.getSelectedRows();
    for (int i = ilist.length - 1; i >= 0; i--) {
      list.add(tableModel.getValueAt(modelIndex(ilist[i]), keyCol));
    }
    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);
    loadSelectedRow(t, list, keyCol);
  }
}
 
Example #29
Source File: JTableHeaderEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object getDesignValue(Object target) {
    // PENDING
    JTableHeader header = null;
    if (target instanceof javax.swing.JTable) {
        header = ((javax.swing.JTable)target).getTableHeader();
        header.setResizingAllowed(resizingAllowed);
        header.setReorderingAllowed(reorderingAllowed);                
    }
    return header;
}
 
Example #30
Source File: JTableHeaderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTableHeader.getHeaderRect(int)} through queue
 */
public Rectangle getHeaderRect(final int i) {
    return (runMapping(new MapAction<Rectangle>("getHeaderRect") {
        @Override
        public Rectangle map() {
            return ((JTableHeader) getSource()).getHeaderRect(i);
        }
    }));
}