本文整理匯總了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);
}