use of javax.swing.table.JTableHeader in project groovy by apache.
the class TableSorter method addMouseListenerToHeaderInTable.
// There is no-where else to put this.
// Add a mouse listener to the Table to trigger a table sort
// when a column heading is clicked in the JTable.
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);
if (e.getClickCount() == 1 && column != -1) {
if (lastSortedColumn == column)
ascending = !ascending;
sorter.sortByColumn(column, ascending);
lastSortedColumn = column;
}
}
};
JTableHeader th = tableView.getTableHeader();
th.addMouseListener(listMouseListener);
}
use of javax.swing.table.JTableHeader in project pcgen by PCGen.
the class CharacterHPDialog method initComponents.
private void initComponents() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JTable table = new JTable(tableModel) {
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (column == 5) {
//TODO: the max roll should be calculated in a different manner
String hd = levels.getClassTaken(levels.getElementAt(row)).getHD();
int max = NumberUtils.toInt(hd);
return new IntegerEditor(1, max);
} else {
return super.getCellEditor(row, column);
}
}
};
table.setDefaultRenderer(JButton.class, new Renderer());
table.setDefaultEditor(JButton.class, new Editor());
table.setCellSelectionEnabled(false);
table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height);
JTableHeader header = table.getTableHeader();
header.setReorderingAllowed(false);
JScrollPane scrollPane = new JScrollPane(table);
pane.add(scrollPane, BorderLayout.CENTER);
Box box = Box.createHorizontalBox();
box.add(new JLabel("Total Hp:"));
box.add(Box.createHorizontalStrut(3));
final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() {
@Override
public void referenceChanged(ReferenceEvent<Integer> e) {
totalHp.setText(e.getNewReference().toString());
}
};
ReferenceFacade<Integer> hpRef = character.getTotalHPRef();
totalHp.setText(hpRef.get().toString());
hpRef.addReferenceListener(hpListener);
box.add(totalHp);
box.add(Box.createHorizontalStrut(5));
JButton button = new JButton("Reroll All");
button.setActionCommand("Reroll");
button.addActionListener(this);
box.add(button);
box.add(Box.createHorizontalGlue());
button = new JButton("Close");
button.setActionCommand("Close");
button.addActionListener(this);
box.add(button);
pane.add(box, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
//Make sure to remove the listeners so that the garbage collector can
//dispose of this dialog and prevent a memory leak
levels.removeHitPointListener(tableModel);
character.getTotalHPRef().removeReferenceListener(hpListener);
}
});
Utility.installEscapeCloseOperation(this);
}
use of javax.swing.table.JTableHeader in project pcgen by PCGen.
the class PostLevelUpDialog method initComponents.
private void initComponents() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JTable table = new JTable(tableModel) {
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {
//TODO: the max roll should be calculated in a different manner
String hd = levels.getClassTaken(levels.getElementAt(row + oldLevel)).getHD();
int max = NumberUtils.toInt(hd);
return new SpinnerEditor(new SpinnerNumberModel(1, 1, max, 1));
}
return super.getCellEditor(row, column);
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {
return new SpinnerRenderer();
}
return super.getCellRenderer(row, column);
}
};
table.setCellSelectionEnabled(false);
table.setRowHeight(new JSpinner().getPreferredSize().height);
JTableHeader header = table.getTableHeader();
header.setReorderingAllowed(false);
JScrollPane scrollPane = new JScrollPane(table);
pane.add(scrollPane, BorderLayout.CENTER);
Box box = Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
//$NON-NLS-1$
JButton button = new JButton(LanguageBundle.getString("in_close"));
//$NON-NLS-1$
button.setMnemonic(LanguageBundle.getMnemonic("in_mn_close"));
//$NON-NLS-1$
button.setActionCommand("Close");
button.addActionListener(this);
box.add(button);
pane.add(box, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
//Make sure to remove the listeners so that the garbage collector can
//dispose of this dialog and prevent a memory leak
levels.removeHitPointListener(tableModel);
}
});
Utility.installEscapeCloseOperation(this);
}
use of javax.swing.table.JTableHeader in project EnrichmentMapApp by BaderLab.
the class ColumnHeaderRankOptionRenderer method menuButtonClicked.
private void menuButtonClicked(JTable table, JButton button) {
JTableHeader header = table.getTableHeader();
List<RankingOption> rankOptions = mainPanel.getAllRankingOptions();
JPopupMenu menu = new JPopupMenu();
for (RankingOption rankOption : rankOptions) {
JMenuItem item = new JCheckBoxMenuItem(rankOption.getName());
item.setSelected(rankOption == mainPanel.getSelectedRankOption());
SwingUtil.makeSmall(item);
menu.add(item);
item.addActionListener(e -> mainPanel.updateSetting_RankOption(rankOption));
}
int y = button.getHeight();
int x = 0;
for (int i = 0; i < colIndex; i++) {
TableColumn tableColumn = table.getColumnModel().getColumn(i);
x += tableColumn.getWidth();
}
menu.show(header, x, y);
}
use of javax.swing.table.JTableHeader in project EnrichmentMapApp by BaderLab.
the class ColumnHeaderRankOptionRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, final Object value, boolean isSelected, boolean hasFocus, int row, int col) {
// Convert RankingOption to display String
String text = null;
if (value instanceof RankingOption) {
RankingOption rankingOption = (RankingOption) value;
text = rankingOption.getTableHeaderText();
} else if (value instanceof RankOptionErrorHeader) {
RankOptionErrorHeader headerValue = (RankOptionErrorHeader) value;
text = headerValue.getRankingOption().getTableHeaderText();
}
// Use the default renderer to paint the header nicely (with sort arrows)
JTableHeader header = table.getTableHeader();
TableCellRenderer delegate = table.getTableHeader().getDefaultRenderer();
Component component = delegate.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, col);
// Create the panel
JButton button = new JButton("Sort");
SwingUtil.makeSmall(button);
if (isAquaLAF())
button.putClientProperty("JButton.buttonType", "gradient");
button.addActionListener(e -> menuButtonClicked(table, button));
JPanel buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(button, BorderLayout.CENTER);
buttonPanel.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
buttonPanel.setForeground(header.getForeground());
buttonPanel.setBackground(header.getBackground());
JPanel panel = new JPanel(new BorderLayout());
panel.setForeground(header.getForeground());
panel.setBackground(header.getBackground());
panel.add(component, BorderLayout.CENTER);
panel.add(buttonPanel, BorderLayout.NORTH);
if (value instanceof RankOptionErrorHeader) {
JLabel icon = new JLabel(IconManager.ICON_TIMES_CIRCLE);
icon.setForeground(Color.RED.darker());
icon.setFont(iconManager.getIconFont(13.0f));
icon.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
icon.setOpaque(false);
panel.add(icon, BorderLayout.WEST);
}
// Add mouse listener
if (mouseListener != null) {
header.removeMouseListener(mouseListener);
}
header.addMouseListener(mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int col = header.columnAtPoint(e.getPoint());
if (col == colIndex)
if (e.getY() <= button.getHeight())
button.doClick();
else
sortColumn(table);
else
sortOrder = null;
}
});
return panel;
}
Aggregations