Re: JTree application



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
.



Relevant Pages

  • Re: JTree application
    ... I'D like to have the string separated in 2 parts, ... "THIS IS" should be bold face, ... "string to show" is normal face. ... Andrew T. ...
    (comp.lang.java.programmer)
  • Connecting to Sharepoint Problem
    ... String bstrCurrentFolderUrl, Boolean& pbCanCustomizePages, Boolean& ... pVerGhostedSetupPath, UInt32& pdwPartCount, Object& pvarMetaData, ... pbstrRedirectUrl, Boolean& pbObjectIsList, Guid& pgListId, UInt32& ...
    (microsoft.public.biztalk.general)
  • Re: Connecting to Sharepoint Problem
    ... String bstrCurrentFolderUrl, Boolean& pbCanCustomizePages, Boolean& ... pVerGhostedSetupPath, UInt32& pdwPartCount, Object& pvarMetaData, ... pbstrRedirectUrl, Boolean& pbObjectIsList, Guid& pgListId, UInt32& ...
    (microsoft.public.biztalk.general)
  • RE: installation WSS 3.0
    ... <exception, Boolean breakConnection) ... <owningObject, SqlConnectionString connectionOptions, String newPassword, ... <newDatabaseId, String strDatabaseServer, String strDatabaseName, String ... <databaseServer, String databaseName, String databaseUsername, String ...
    (microsoft.public.windows.server.sbs)
  • Die Datei, die Sie zu speichern oder wiederherstellen versuchen, wurde von den Webserveradministrato
    ... bstrUrl, Byte bPageView, Byte bPageMode, Byte bGetBuildDependencySet, ... String bstrCurrentFolderUrl, Boolean& pbCanCustomizePages, Boolean& ... Object& pvarMultipleMeetingDoclibRootFolders, String& ...
    (microsoft.public.de.german.sharepointportalserver)