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

The following examples show how to use javax.swing.table.JTableHeader#setReorderingAllowed() . 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: SkillPointTableModel.java    From pcgen with GNU Lesser General Public License v2.1 7 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 2
Source File: JTableHeaderEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Object getDesignValue() {
    Object value = null;
    try {
        value = property.getTargetValue();
        if (value instanceof JTableHeader) {
            JTableHeader header = (JTableHeader)value;
            header.setResizingAllowed(resizingAllowed);
            header.setReorderingAllowed(reorderingAllowed);
        }
    } catch (IllegalAccessException iaex) {
        Logger.getLogger(getClass().getName()).log(Level.INFO, iaex.getMessage(), iaex);
    } catch (InvocationTargetException itex) {
        Logger.getLogger(getClass().getName()).log(Level.INFO, itex.getMessage(), itex);
    }
    return value;
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());

  String[] columnNames = {"String", "Integer", "Boolean"};
  Object[][] data = {
    {"aaa", 12, true}, {"bbb", 5, false},
    {"CCC", 92, true}, {"DDD", 0, false}
  };
  TableModel model = new DefaultTableModel(data, columnNames) {
    @Override public Class<?> getColumnClass(int column) {
      return getValueAt(0, column).getClass();
    }
  };
  JTable table = new JTable(model);
  JTableHeader header = table.getTableHeader();
  header.setReorderingAllowed(false);

  JCheckBox checkBox = new JCheckBox("disable column dragging", true);
  checkBox.addActionListener(e -> header.setReorderingAllowed(!((JCheckBox) e.getSource()).isSelected()));

  add(checkBox, BorderLayout.NORTH);
  add(new JScrollPane(table));
  setPreferredSize(new Dimension(320, 240));
}
 
Example 4
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 5
Source File: ClassLevelTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void initializeTable(JTable classLevelTable)
{
	JTableHeader tableHeader = classLevelTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);
	TableColumnModel columnModel = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
	columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true));
	classLevelTable.setColumnModel(columnModel);
	classLevelTable.setAutoCreateColumnsFromModel(false);
	classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
	classLevelTable.setFocusable(false);
	classLevelTable.setCellSelectionEnabled(false);
	classLevelTable.setRowHeight(20);
}
 
Example 6
Source File: ListTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ListTable(ListWrappingTableModel tableModel) {
    super(tableModel);
    setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
    setRowSelectionAllowed(true);
    setDragEnabled(false);
    final JTableHeader header = getTableHeader();
    header.setReorderingAllowed(false);
    final TableCellRenderer delegate = header.getDefaultRenderer();
    final TableCellRenderer newRenderer = new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            final Component component = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            // to display the table header in disabled state when the table is disabled.
            component.setEnabled(table.isEnabled());
            return component;
        }
    };
    header.setDefaultRenderer(newRenderer);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
 
Example 7
Source File: MainPanel.java    From java-swing-tips with 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 8
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private void initCellSize(int size) {
  setRowHeight(size);
  JTableHeader tableHeader = getTableHeader();
  tableHeader.setResizingAllowed(false);
  tableHeader.setReorderingAllowed(false);
  TableColumnModel m = getColumnModel();
  for (int i = 0; i < m.getColumnCount(); i++) {
    TableColumn col = m.getColumn(i);
    col.setMinWidth(size);
    col.setMaxWidth(size);
  }
  setBorder(BorderFactory.createLineBorder(Color.BLACK));
}
 
Example 9
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());

  monthTable.setDefaultRenderer(LocalDate.class, new CalendarTableRenderer());
  monthTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  monthTable.setCellSelectionEnabled(true);
  monthTable.setFillsViewportHeight(true);

  JTableHeader header = monthTable.getTableHeader();
  header.setResizingAllowed(false);
  header.setReorderingAllowed(false);
  ((JLabel) header.getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER);

  updateMonthView(LocalDate.of(2020, 8, 1));

  JButton prev = new JButton("<");
  prev.addActionListener(e -> updateMonthView(getCurrentLocalDate().minusMonths(1)));

  JButton next = new JButton(">");
  next.addActionListener(e -> updateMonthView(getCurrentLocalDate().plusMonths(1)));

  JPanel p = new JPanel(new BorderLayout());
  p.add(monthLabel);
  p.add(prev, BorderLayout.WEST);
  p.add(next, BorderLayout.EAST);

  JScrollPane scroll = new JScrollPane(monthTable);
  scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
  scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

  add(p, BorderLayout.NORTH);
  add(scroll);
  setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  setPreferredSize(new Dimension(320, 240));
}
 
Example 10
Source File: UPbFractionTable.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param myFrame
 * @param mySample
 */
public void setMySample(ETReduxFrame myFrame, SampleInterface mySample) {
    this.mySample = mySample;

    setModel(new UPbFractionTableModel(myFrame, mySample));

    JTableHeader header = getTableHeader();
    header.setReorderingAllowed(false);
    float[] myLightBlue = Color.RGBtoHSB(241, 246, 254, null);
    header.setBackground(Color.getHSBColor(myLightBlue[0], myLightBlue[1], myLightBlue[2]));
    header.setDefaultRenderer(new HeaderCellRendererToLabel());


}
 
Example 11
Source File: CardsJTable.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private void setDefaultColumnProperties() {
    final TableColumnModel cm = getColumnModel();
    // set initial column widths.
    for (int i = 0; i < cm.getColumnCount(); i++) {
        cm.getColumn(i).setMinWidth(CardTableColumn.getMinWidth(i));
        cm.getColumn(i).setPreferredWidth(CardTableColumn.getMinWidth(i));
    }
    final JTableHeader header = getTableHeader();
    header.setReorderingAllowed(true);
    final DefaultTableCellRenderer renderer =
            (DefaultTableCellRenderer) header.getDefaultRenderer();
    // center the column header captions.
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
}
 
Example 12
Source File: GameStatsJTable.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private void setDefaultColumnProperties() {
    final TableColumnModel cm = getColumnModel();
    // set initial column widths.
    for (int i = 0; i < cm.getColumnCount(); i++) {
        cm.getColumn(i).setMinWidth(50);
        cm.getColumn(i).setPreferredWidth(50);
    }
    final JTableHeader header = getTableHeader();
    header.setReorderingAllowed(true);
    final DefaultTableCellRenderer renderer =
            (DefaultTableCellRenderer) header.getDefaultRenderer();
    // center the column header captions.
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
}
 
Example 13
Source File: TubesProjectConfigPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public TubeTable(boolean client) {
    super();
    this.client = client;

    JTableHeader header = getTableHeader();
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);

    ListSelectionModel model = getSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    model.addListSelectionListener(new TubeListSelectionListener(client));
}
 
Example 14
Source File: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private JScrollPane createVariablesTable(final String labelName) {
    variablesTable = new JTable();
    variablesTable.setName(labelName);
    variablesTable.setRowSelectionAllowed(true);
    bindingCtx.bind("variables", new VariablesTableAdapter(variablesTable));
    bindingCtx.bindEnabledState("variables", false, "updateMode", true);
    variablesTable.addMouseListener(createExpressionEditorMouseListener(variablesTable, false));

    final JTableHeader tableHeader = variablesTable.getTableHeader();
    tableHeader.setName(labelName);
    tableHeader.setReorderingAllowed(false);
    tableHeader.setResizingAllowed(true);

    final TableColumnModel columnModel = variablesTable.getColumnModel();
    columnModel.setColumnSelectionAllowed(false);

    final TableColumn nameColumn = columnModel.getColumn(0);
    nameColumn.setPreferredWidth(100);
    nameColumn.setCellRenderer(new TCR());

    final TableColumn expressionColumn = columnModel.getColumn(1);
    expressionColumn.setPreferredWidth(400);
    expressionColumn.setCellRenderer(new TCR());
    final ExprEditor exprEditor = new ExprEditor(false);
    expressionColumn.setCellEditor(exprEditor);
    bindingCtx.addPropertyChangeListener("updateMode", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            final boolean enabled = Boolean.FALSE.equals(evt.getNewValue());
            exprEditor.button.setEnabled(enabled);
        }
    });

    final JScrollPane scrollPane = new JScrollPane(variablesTable);
    scrollPane.setName(labelName);
    scrollPane.setPreferredSize(new Dimension(PREFERRED_TABLE_WIDTH, 150));

    return scrollPane;
}
 
Example 15
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 16
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void setColumnReorderingAllowed(boolean columnReorderingAllowed) {
    JTableHeader tableHeader = impl.getTableHeader();
    tableHeader.setReorderingAllowed(columnReorderingAllowed);
}
 
Example 17
Source File: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private JScrollPane createConditionsTable(final String labelName) {
    conditionsTable = new JTable() {
        private static final long serialVersionUID = 1L;

        @Override
        public Class getColumnClass(int column) {
            if (column == 2) {
                return Boolean.class;
            } else {
                return super.getColumnClass(column);
            }
        }
    };
    conditionsTable.setName(labelName);
    conditionsTable.setRowSelectionAllowed(true);
    bindingCtx.bind("conditions", new ConditionsTableAdapter(conditionsTable));
    bindingCtx.bindEnabledState("conditions", false, "updateMode", true);
    conditionsTable.addMouseListener(createExpressionEditorMouseListener(conditionsTable, true));

    final JTableHeader tableHeader = conditionsTable.getTableHeader();
    tableHeader.setName(labelName);
    tableHeader.setReorderingAllowed(false);
    tableHeader.setResizingAllowed(true);

    final TableColumnModel columnModel = conditionsTable.getColumnModel();
    columnModel.setColumnSelectionAllowed(false);

    final TableColumn nameColumn = columnModel.getColumn(0);
    nameColumn.setPreferredWidth(100);
    nameColumn.setCellRenderer(new TCR());

    final TableColumn expressionColumn = columnModel.getColumn(1);
    expressionColumn.setPreferredWidth(360);
    expressionColumn.setCellRenderer(new TCR());
    final ExprEditor cellEditor = new ExprEditor(true);
    expressionColumn.setCellEditor(cellEditor);
    bindingCtx.addPropertyChangeListener("updateMode", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            final boolean enabled = Boolean.FALSE.equals(evt.getNewValue());
            cellEditor.button.setEnabled(enabled);
        }
    });


    final TableColumn outputColumn = columnModel.getColumn(2);
    outputColumn.setPreferredWidth(40);

    final JScrollPane pane = new JScrollPane(conditionsTable);
    pane.setName(labelName);
    pane.setPreferredSize(new Dimension(PREFERRED_TABLE_WIDTH, 80));

    return pane;
}
 
Example 18
Source File: JXTableRowHeader.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public JTableHeader getTableHeader() {
    JTableHeader header = headerTable.getTableHeader();
    header.setReorderingAllowed(false);
    header.setResizingAllowed(false);
    return header;
}
 
Example 19
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());
  String[] columnNames = {"A", "B", "C"};
  Object[][] data = {
      {"aaa", "ee ee", "l"}, {"bbb", "ff", "ggg"},
      {"CCC", "kkk", "jj"}, {"DDD", "ii", "hhh"}
  };
  TableModel model = new DefaultTableModel(data, columnNames) {
    @Override public Class<?> getColumnClass(int column) {
      return getValueAt(0, column).getClass();
    }
  };
  JTable table = new JTable(model);
  table.setAutoCreateRowSorter(true);
  table.setRowSelectionAllowed(true);
  table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  // table.setFillsViewportHeight(true);
  table.setIntercellSpacing(new Dimension());
  table.setShowGrid(false);
  // table.setShowHorizontalLines(false);
  // table.setShowVerticalLines(false);
  table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
  JTableHeader tableHeader = table.getTableHeader();
  tableHeader.setReorderingAllowed(false);

  // TableColumn col = table.getColumnModel().getColumn(0);
  // col.setMinWidth(50);
  // col.setMaxWidth(50);
  // col.setResizable(false);

  TableCellRenderer defaultRenderer = table.getDefaultRenderer(Object.class);
  UnderlineCellRenderer underlineRenderer = new UnderlineCellRenderer();
  DefaultCellEditor ce = (DefaultCellEditor) table.getDefaultEditor(Object.class);

  JCheckBox modelCheck = new JCheckBox("edit the cell on single click");
  modelCheck.addActionListener(e -> {
    if (modelCheck.isSelected()) {
      table.setDefaultRenderer(Object.class, underlineRenderer);
      table.addMouseListener(underlineRenderer);
      table.addMouseMotionListener(underlineRenderer);
      ce.setClickCountToStart(1);
    } else {
      table.setDefaultRenderer(Object.class, defaultRenderer);
      table.removeMouseListener(underlineRenderer);
      table.removeMouseMotionListener(underlineRenderer);
      ce.setClickCountToStart(2);
    }
  });
  JScrollPane scrollPane = new JScrollPane(table);
  scrollPane.getViewport().setBackground(Color.WHITE);
  add(modelCheck, BorderLayout.NORTH);
  add(scrollPane);
  setPreferredSize(new Dimension(320, 240));
}
 
Example 20
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());

  monthTable.setDefaultRenderer(LocalDate.class, new CalendarTableRenderer());
  monthTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  monthTable.setCellSelectionEnabled(true);
  monthTable.setRowHeight(20);
  monthTable.setFillsViewportHeight(true);

  JTableHeader header = monthTable.getTableHeader();
  header.setResizingAllowed(false);
  header.setReorderingAllowed(false);
  ((JLabel) header.getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER);

  ListSelectionListener selectionListener = e -> {
    if (!e.getValueIsAdjusting()) {
      LocalDate ld = (LocalDate) monthTable.getValueAt(monthTable.getSelectedRow(), monthTable.getSelectedColumn());
      dateLabel.setText(ld.toString());
    }
  };
  monthTable.getSelectionModel().addListSelectionListener(selectionListener);
  monthTable.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);

  updateMonthView(realLocalDate);

  JButton prev = new JButton("<");
  prev.addActionListener(e -> updateMonthView(getCurrentLocalDate().minusMonths(1)));

  JButton next = new JButton(">");
  next.addActionListener(e -> updateMonthView(getCurrentLocalDate().plusMonths(1)));

  JPanel p = new JPanel(new BorderLayout());
  p.add(monthLabel);
  p.add(prev, BorderLayout.WEST);
  p.add(next, BorderLayout.EAST);

  add(p, BorderLayout.NORTH);
  add(new JScrollPane(monthTable));
  add(dateLabel, BorderLayout.SOUTH);
  setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  setPreferredSize(new Dimension(320, 240));
}