use of javax.swing.table.DefaultTableCellRenderer in project Eidolons by IDemiurge.
the class DC_InfoPanelRenderer method getDefaultComp.
private Component getDefaultComp(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value.toString().equals(G_PROPS.EMPTY_VALUE.toString()) || table.getValueAt(row, 0).toString().equals(G_PROPS.EMPTY_VALUE.toString())) {
component = new DefaultTableCellRenderer().getTableCellRendererComponent(table, "", false, hasFocus, row, column);
component.setBackground(Color.BLACK);
table.setRowHeight(row, table.getRowHeight() / 2);
return component;
}
return component;
}
use of javax.swing.table.DefaultTableCellRenderer in project CoreNLP by stanfordnlp.
the class InputPanel method showHistory.
private void showHistory() {
if (historyFrame == null) {
historyFrame = new JFrame("Statistics History");
} else {
historyFrame.setVisible(false);
historyFrame = new JFrame("Statistics History");
}
historyFrame.setLayout(new GridLayout(1, 0));
Object[][] entries = new Object[historyList.size()][3];
for (int i = 0; i < historyList.size(); i++) {
entries[i] = historyList.get(i).toArray();
}
DefaultTableModel tableModel = new TregexGUITableModel(entries, HistoryEntry.columnNamesArray());
JTable statTable = new JTable(tableModel);
DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) statTable.getDefaultRenderer(String.class);
dtcr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
JScrollPane scroller = new JScrollPane(statTable);
historyFrame.add(scroller);
historyFrame.pack();
historyFrame.setLocationRelativeTo(TregexGUI.getInstance());
historyFrame.setBackground(Color.WHITE);
historyFrame.setVisible(true);
historyFrame.repaint();
}
use of javax.swing.table.DefaultTableCellRenderer in project gitblit by gitblit.
the class RepositoriesPanel method initialize.
private void initialize() {
final JButton browseRepository = new JButton(Translation.get("gb.browse"));
browseRepository.setEnabled(false);
browseRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RepositoryModel model = getSelectedRepositories().get(0);
String url = gitblit.getURL("summary", model.name, null);
Utils.browse(url);
}
});
JButton refreshRepositories = new JButton(Translation.get("gb.refresh"));
refreshRepositories.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshRepositories();
}
});
clearCache = new JButton(Translation.get("gb.clearCache"));
clearCache.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clearCache();
}
});
createRepository = new JButton(Translation.get("gb.create"));
createRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createRepository();
}
});
editRepository = new JButton(Translation.get("gb.edit"));
editRepository.setEnabled(false);
editRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editRepository(getSelectedRepositories().get(0));
}
});
delRepository = new JButton(Translation.get("gb.delete"));
delRepository.setEnabled(false);
delRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteRepositories(getSelectedRepositories());
}
});
final JButton subscribeRepository = new JButton(Translation.get("gb.subscribe") + "...");
subscribeRepository.setEnabled(false);
subscribeRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<FeedModel> feeds = gitblit.getAvailableFeeds(getSelectedRepositories().get(0));
subscribeFeeds(feeds);
}
});
final JButton logRepository = new JButton(Translation.get("gb.log") + "...");
logRepository.setEnabled(false);
logRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RepositoryModel model = getSelectedRepositories().get(0);
showSearchDialog(false, model);
}
});
final JButton searchRepository = new JButton(Translation.get("gb.search") + "...");
searchRepository.setEnabled(false);
searchRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RepositoryModel model = getSelectedRepositories().get(0);
showSearchDialog(true, model);
}
});
SubscribedRepositoryRenderer nameRenderer = new SubscribedRepositoryRenderer(gitblit);
IndicatorsRenderer typeRenderer = new IndicatorsRenderer();
DefaultTableCellRenderer sizeRenderer = new DefaultTableCellRenderer();
sizeRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
sizeRenderer.setForeground(new Color(0, 0x80, 0));
DefaultTableCellRenderer ownerRenderer = new DefaultTableCellRenderer();
ownerRenderer.setForeground(Color.gray);
ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
tableModel = new RepositoriesTableModel();
defaultSorter = new TableRowSorter<RepositoriesTableModel>(tableModel);
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
table.setRowSorter(defaultSorter);
table.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal());
setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1);
setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100);
setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1);
setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean singleSelection = table.getSelectedRowCount() == 1;
boolean selected = table.getSelectedRow() > -1;
if (singleSelection) {
RepositoryModel repository = getSelectedRepositories().get(0);
browseRepository.setEnabled(repository.hasCommits);
logRepository.setEnabled(repository.hasCommits);
searchRepository.setEnabled(repository.hasCommits);
subscribeRepository.setEnabled(repository.hasCommits);
} else {
browseRepository.setEnabled(false);
logRepository.setEnabled(false);
searchRepository.setEnabled(false);
subscribeRepository.setEnabled(false);
}
delRepository.setEnabled(selected);
if (selected) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
RepositoryModel model = ((RepositoriesTableModel) table.getModel()).list.get(modelRow);
editRepository.setEnabled(singleSelection && (gitblit.allowManagement() || gitblit.isOwner(model)));
} else {
editRepository.setEnabled(false);
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && gitblit.allowManagement()) {
editRepository(getSelectedRepositories().get(0));
}
}
});
filterTextfield = new JTextField();
filterTextfield.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterRepositories(filterTextfield.getText());
}
});
filterTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
filterRepositories(filterTextfield.getText());
}
});
JPanel repositoryFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
repositoryFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
repositoryFilterPanel.add(filterTextfield, BorderLayout.CENTER);
JPanel repositoryTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
repositoryTablePanel.add(repositoryFilterPanel, BorderLayout.NORTH);
repositoryTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
JPanel repositoryControls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
repositoryControls.add(clearCache);
repositoryControls.add(refreshRepositories);
repositoryControls.add(browseRepository);
repositoryControls.add(createRepository);
repositoryControls.add(editRepository);
repositoryControls.add(delRepository);
repositoryControls.add(subscribeRepository);
repositoryControls.add(logRepository);
repositoryControls.add(searchRepository);
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
header = new HeaderPanel(Translation.get("gb.repositories"), "git-orange-16x16.png");
add(header, BorderLayout.NORTH);
add(repositoryTablePanel, BorderLayout.CENTER);
add(repositoryControls, BorderLayout.SOUTH);
}
use of javax.swing.table.DefaultTableCellRenderer in project java-swing-tips by aterai.
the class FileListTable method updateUI.
@Override
public void updateUI() {
// [JDK-6788475]
// Changing to Nimbus LAF and back doesn't reset look and feel of JTable completely
// https://bugs.openjdk.java.net/browse/JDK-6788475
// XXX: set dummy ColorUIResource
setSelectionForeground(new ColorUIResource(Color.RED));
setSelectionBackground(new ColorUIResource(Color.RED));
removeMouseMotionListener(rbl);
removeMouseListener(rbl);
setDefaultRenderer(Object.class, null);
super.updateUI();
rbl = new RubberBandingListener();
addMouseMotionListener(rbl);
addMouseListener(rbl);
putClientProperty("Table.isFileList", Boolean.TRUE);
setCellSelectionEnabled(true);
setIntercellSpacing(new Dimension());
setShowGrid(false);
setAutoCreateRowSorter(true);
setFillsViewportHeight(true);
TableCellRenderer r = new DefaultTableCellRenderer();
setDefaultRenderer(Object.class, (table, value, isSelected, hasFocus, row, column) -> r.getTableCellRendererComponent(table, value, false, false, row, column));
TableColumn col = getColumnModel().getColumn(0);
col.setCellRenderer(new FileNameRenderer(this));
col.setPreferredWidth(200);
col = getColumnModel().getColumn(1);
col.setPreferredWidth(300);
}
use of javax.swing.table.DefaultTableCellRenderer in project druid by alibaba.
the class GroupableTableHeaderUI method getHeaderHeight.
public int getHeaderHeight() {
int height = 0;
TableColumnModel columnModel = header.getColumnModel();
for (int column = 0; column < columnModel.getColumnCount(); column++) {
TableColumn aColumn = columnModel.getColumn(column);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = new DefaultTableCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
setHorizontalAlignment(JLabel.CENTER);
setText((value == null) ? "" : value.toString());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
}
};
}
Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, column);
int cHeight = comp.getPreferredSize().height;
Enumeration<ColumnGroup> enumeration = ((GroupableTableHeader) header).getColumnGroups(aColumn);
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
ColumnGroup cGroup = (ColumnGroup) enumeration.nextElement();
cHeight += cGroup.getSize(header.getTable()).height;
}
}
height = Math.max(height, cHeight);
}
height = Math.max(height, m_height);
return height;
}
Aggregations