Re: JTree application
- From: Rogan Dawes <discard@xxxxxxxxxxxx>
- Date: Mon, 26 Jun 2006 11:06:39 +0200
Andrew T. wrote:
giangiammy@xxxxxxxxx wrote:
..
new DefaultMutableTreeNode("THIS IS: string to show");
I'D like to have the string separated in 2 parts,
"THIS IS" should be bold face, while
"string to show" is normal face.
Is there a way to divide that string and have it shown
with different fonts.
Most Swing components accept HTML, so you might try
something like..
new DefaultMutableTreeNode(
"<html><body><b>THIS IS:</b> string to show");
HTH
Andrew T.
That would work as a hack, but I suspect that you really want to use a TreeCellRenderer to do the job properly. Not meaning to dismiss Andrew's approach, which I use below, but because I suspect that you actually want to do something a bit more complicated than you are actually asking.
For example, extending DefaultTreeCellRenderer, you could create your nodes using
new DefaultMutableTreeNode("string to show");
and render it with
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
JLable label = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
label.setText("<html><body><b>THIS IS:</b> " + value.toString());
return label;
}
This is more of a building block to get you started building your own more customised renderers.
Regards,
Rogan
.
- Follow-Ups:
- Re: JTree application
- From: giangiammy@xxxxxxxxx
- Re: JTree application
- References:
- JTree application
- From: giangiammy@xxxxxxxxx
- Re: JTree application
- From: Andrew T.
- JTree application
- Prev by Date: Re: JTree application
- Next by Date: Re: Trouble in entering numbers after decimal points - JFormattedTextField
- Previous by thread: Re: JTree application
- Next by thread: Re: JTree application
- Index(es):
Relevant Pages
|