本文整理汇总了Java中javax.swing.tree.DefaultTreeCellRenderer类的典型用法代码示例。如果您正苦于以下问题:Java DefaultTreeCellRenderer类的具体用法?Java DefaultTreeCellRenderer怎么用?Java DefaultTreeCellRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultTreeCellRenderer类属于javax.swing.tree包,在下文中一共展示了DefaultTreeCellRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateIcons
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public static void updateIcons(JTree tree) {
Font defaultFont = UIManager.getFont("Tree.font");
Font currentFont = tree.getFont();
double newScale = (double)
currentFont.getSize2D() / defaultFont.getSize2D();
DefaultTreeCellRenderer renderer =
(DefaultTreeCellRenderer) tree.getCellRenderer();
renderer.setOpenIcon(
scale(UIManager.getIcon("Tree.openIcon"), newScale, tree));
renderer.setClosedIcon(
scale(UIManager.getIcon("Tree.closedIcon"), newScale, tree));
renderer.setLeafIcon(
scale(UIManager.getIcon("Tree.leafIcon"), newScale, tree));
Collection<Integer> iconSizes = Arrays.asList(
renderer.getOpenIcon().getIconHeight(),
renderer.getClosedIcon().getIconHeight(),
renderer.getLeafIcon().getIconHeight());
// Convert points to pixels
Point2D p = new Point2D.Float(0, currentFont.getSize2D());
FontRenderContext context =
tree.getFontMetrics(currentFont).getFontRenderContext();
context.getTransform().transform(p, p);
int fontSizeInPixels = (int) Math.ceil(p.getY());
tree.setRowHeight(
Math.max(fontSizeInPixels, Collections.max(iconSizes) + 2));
}
示例2: getTreeCellRendererComponent
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
((DefaultTreeCellRenderer) renderer).setLeafIcon(null);
((DefaultTreeCellRenderer) renderer).setIcon(null);
((DefaultTreeCellRenderer) renderer).setOpenIcon(null);
((DefaultTreeCellRenderer) renderer).setClosedIcon(null);
TreePath path = tree.getPathForRow(row);
if (path != null) {
if (selectionModel.isPathSelected(path, true)) {
checkBox.setState(Boolean.TRUE);
} else {
checkBox.setState(selectionModel.isPartiallySelected(path) ? null : Boolean.FALSE);
}
}
removeAll();
add(checkBox, BorderLayout.WEST);
add(renderer, BorderLayout.CENTER);
return this;
}
示例3: CellRenderer
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* Empty constructor with the correct visibility.
* @param tree the enclosing checkbox tree
*/
CellRenderer(CheckboxTree tree) {
this.tree = tree;
this.jLabel = new DefaultTreeCellRenderer();
this.jLabel.setOpenIcon(null);
this.jLabel.setLeafIcon(null);
this.jLabel.setClosedIcon(null);
this.jLabel.setBorder(INSET_BORDER);
this.checkbox = new JCheckBox();
this.checkbox.setOpaque(false);
setLayout(new BorderLayout());
add(this.jLabel, BorderLayout.CENTER);
add(this.checkbox, CheckboxTree.CHECKBOX_ORIENTATION);
setBorder(new EmptyBorder(0, 2, 0, 0));
setComponentOrientation(this.tree.getComponentOrientation());
setOpaque(false);
}
示例4: UpdateUIRecursionTest
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public UpdateUIRecursionTest() {
super("UpdateUIRecursionTest");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
String[] listData = {
"First", "Second", "Third", "Fourth", "Fifth", "Sixth"
};
tree = new JTree(listData);
renderer = new DefaultTreeCellRenderer();
getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
tree.setCellRenderer(this);
setVisible(true);
}
示例5: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI ()
{
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例6: RecordTreeCellEditor
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public RecordTreeCellEditor(RecordTree tree,DefaultTreeCellRenderer renderer) {
super(tree,renderer);
cellEditor = new JTextArea();
codedCellEditor = new JTextField();
label = new JLabel();
coder = new JButton(new ImageIcon(getClass().getResource(
"/com/gint/app/bisis4/client/images/coder.gif")));
lookup = new CharacterLookup(BisisApp.getMainFrame());
editingContainer = new Container();
this.ownerTree = tree;
regDlg = new RegistryDlg(BisisApp.getMainFrame());
codedCellEditor.addKeyListener(new CellEditorKeyListener());
cellEditor.addKeyListener(new CellEditorKeyListener());
coder.addKeyListener(new CellEditorKeyListener());
coder.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
handleOpenCoder();
}
});
}
示例7: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* UpdateUI is overridden to set the colors of the Tree's renderer
* to match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
final TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr;
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// renderer.setBorderSelectionColor(null);
renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例8: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager
.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager
.getColor("Table.selectionBackground"));
((DefaultTreeCellRenderer)this.getCellRenderer()).setLeafIcon(null);
((DefaultTreeCellRenderer)this.getCellRenderer()).setOpenIcon(null);
((DefaultTreeCellRenderer)this.getCellRenderer()).setClosedIcon(null);
}
}
示例9: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager
.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager
.getColor("Table.selectionBackground"));
}
}
示例10: EventPanel
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public EventPanel(SWEKGroup _group) {
group = _group;
setLayout(new BorderLayout());
SWEKTreeModel.addSWEKTreeModelListener(this);
JTree eventTypeTree = new JTree(new EventPanelModel(group));
eventTypeTree.setEditable(true);
eventTypeTree.setShowsRootHandles(true);
eventTypeTree.setSelectionModel(null);
eventTypeTree.setCellRenderer(new SWEKEventTreeRenderer(eventTypeTree));
eventTypeTree.setCellEditor(new MyTreeCellEditor(eventTypeTree, (DefaultTreeCellRenderer) eventTypeTree.getCellRenderer()));
// workaround for Win HiDpi
if (System.getProperty("jhv.os").equals("windows")) {
eventTypeTree.setRowHeight(new JCheckBox("J").getPreferredSize().height);
}
add(eventTypeTree, BorderLayout.CENTER);
JPanel busyPanel = new JPanel();
busyPanel.setBackground(eventTypeTree.getBackground());
busyPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
busyPanel.add(over);
add(busyPanel, BorderLayout.LINE_END);
}
示例11: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
((DefaultTreeCellRenderer) this.getCellRenderer()).setLeafIcon(null);
((DefaultTreeCellRenderer) this.getCellRenderer()).setOpenIcon(null);
((DefaultTreeCellRenderer) this.getCellRenderer()).setClosedIcon(null);
}
}
示例12: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例13: doNotFillBackground
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public static void doNotFillBackground(@NotNull final JTree tree, @NotNull final DefaultTreeCellRenderer renderer) {
TreeUI ui = tree.getUI();
if (ui instanceof WideSelectionTreeUI) {
if (((WideSelectionTreeUI)ui).isWideSelection()) {
renderer.setOpaque(false);
try {
final Field fillBackground = DefaultTreeCellRenderer.class.getDeclaredField("fillBackground");
fillBackground.setAccessible(true);
fillBackground.set(renderer, false);
}
catch (Exception e) {
// nothing
}
}
}
}
示例14: getTreeCellRendererComponent
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel,
boolean expanded,
boolean leaf, int row,
boolean hasFocus) {
//DefaultTreeCellRenderer.getTreeCellRendererComponent() returns itself
JLabel element = (DefaultTreeCellRenderer) new DefaultTreeCellRenderer().getTreeCellRendererComponent(
tree, value, selected, expanded, leaf, row, hasFocus);
//content of a node, could be a Path (if just directory) or a CommitFile
Object content = ((DefaultMutableTreeNode) value).getUserObject();
//if path, default .toString() method is called
element.setOpaque(true);
//if a CommitFile
if (content instanceof Presenter) {
element = ((Presenter)content).present(element);
}
return element;
}
示例15: CTagFilterTree
import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
* Creates a new filter tree object.
*
* @param tagManager Provides the tags the user can select.
*/
public CTagFilterTree(final ITagManager tagManager) {
super(new CFilterTreeModel(tagManager.getRootTag()));
m_tagManager = tagManager;
setDigIn(false);
final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setOpenIcon(ICON_CONTAINER_TAG);
renderer.setClosedIcon(ICON_CONTAINER_TAG);
renderer.setLeafIcon(ICON_TAG);
setCellRenderer(renderer);
setRootVisible(false);
TreeHelpers.expandAll(this, true);
tagManager.addListener(m_tagManagerListener);
}