Java Code Examples for javax.swing.table.JTableHeader#setDraggedColumn()

The following examples show how to use javax.swing.table.JTableHeader#setDraggedColumn() . 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: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static JTable makeJTable() {
  JTable table = new JTable(4, 3);
  table.setAutoCreateRowSorter(true);
  JPopupMenu popup = new JPopupMenu() {
    @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();
        super.show(c, x, y);
      }
    }
  };
  popup.add("Item 1");
  popup.add("Item 2");
  popup.add("Item 3");
  table.getTableHeader().setComponentPopupMenu(popup);
  return table;
}
 
Example 2
Source File: HeaderComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setupHeader(JTableHeader h) {
    h.setDraggedColumn(isSelected && isPressed ? getColumn() : null);
    
    MouseEvent e = isSelected && !isPressed ?
            new MouseEvent(h, MouseEvent.MOUSE_ENTERED, 1, 0, 1, 1, 0, false) :
            new MouseEvent(h, MouseEvent.MOUSE_EXITED, 1, 0, 0, 0, 0, false);
    h.dispatchEvent(e);
}
 
Example 3
Source File: HeaderComponent.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void setupHeader(JTableHeader h) {
    h.setDraggedColumn(isSelected && isPressed ? getColumn() : null);
    
    MouseEvent e = isSelected && !isPressed ?
            new MouseEvent(h, MouseEvent.MOUSE_ENTERED, 1, 0, 1, 1, 0, false) :
            new MouseEvent(h, MouseEvent.MOUSE_EXITED, 1, 0, 0, 0, 0, false);
    h.dispatchEvent(e);
}
 
Example 4
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;
    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 5
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();
    index = header.columnAtPoint(new Point(x, y));
    if (index >= 0) {
      super.show(c, x, y);
    }
  }
}
 
Example 6
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 7
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);
  }
}