use of javax.swing.plaf.IconUIResource in project java-swing-tips by aterai.
the class EmptyIcon method makeTree.
private static JTree makeTree() {
Icon emptyIcon = new EmptyIcon();
UIManager.put("Tree.expandedIcon", new IconUIResource(emptyIcon));
UIManager.put("Tree.collapsedIcon", new IconUIResource(emptyIcon));
JTree tree = new JTree();
tree.setEditable(true);
tree.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
int row = 0;
while (row < tree.getRowCount()) {
tree.expandRow(row++);
}
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent e) {
// throws ExpandVetoException {
// throw new ExpandVetoException(e, "Tree expansion cancelled");
}
@Override
public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException {
throw new ExpandVetoException(e, "Tree collapse cancelled");
}
});
return tree;
}
use of javax.swing.plaf.IconUIResource in project java-swing-tips by aterai.
the class EmptyIcon method makeRadioPane.
private Box makeRadioPane(JTable table) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL ascendingPath = cl.getResource("example/ascending.png");
URL descendingPath = cl.getResource("example/descending.png");
JRadioButton r0 = new JRadioButton("Default", true);
JRadioButton r1 = new JRadioButton("Empty");
JRadioButton r2 = new JRadioButton("Custom");
ActionListener al = e -> {
JRadioButton r = (JRadioButton) e.getSource();
Icon ascending;
Icon descending;
if (r.equals(r2) && ascendingPath != null && descendingPath != null) {
ascending = new IconUIResource(new ImageIcon(ascendingPath));
descending = new IconUIResource(new ImageIcon(descendingPath));
} else if (r.equals(r1)) {
ascending = new IconUIResource(EMPTY_ICON);
descending = new IconUIResource(EMPTY_ICON);
} else {
// if (r.equals(r0)) { // default
ascending = UIManager.getLookAndFeelDefaults().getIcon("Table.ascendingSortIcon");
descending = UIManager.getLookAndFeelDefaults().getIcon("Table.descendingSortIcon");
}
UIManager.put("Table.ascendingSortIcon", ascending);
UIManager.put("Table.descendingSortIcon", descending);
table.getTableHeader().repaint();
};
Box box1 = Box.createHorizontalBox();
box1.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
ButtonGroup bg = new ButtonGroup();
box1.add(new JLabel("Table Sort Icon: "));
Stream.of(r0, r1, r2).forEach(rb -> {
box1.add(rb);
box1.add(Box.createHorizontalStrut(5));
bg.add(rb);
rb.addActionListener(al);
});
box1.add(Box.createHorizontalGlue());
return box1;
}
Aggregations