How to build a JTree with nodes multi-line Windows L and am FJt

Although I already found 2 ways to build nodes multi-line JTree but both methods work very well in Java by default appearance and when I change my windows look and feel then it fails. I can't understand what is the problem. The two ways by which I build multi line nodes are:

First: Using html in nodes
as the DOSB linea < br > < html > < / html >

Secondly: By implementing TreeRenderer and change it accordingly, such a class is given below
class ModifiedTreeCellRenderer extends JPanel implements TreeCellRenderer {
    protected JLabel icon;
    protected TreeTextArea text;
    
    public ModifiedTreeCellRenderer() {
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        icon = new JLabel() {
            @Override
            public void setBackground(Color color) {
                if (color instanceof ColorUIResource)
                color = null;
                super.setBackground(color);
            }
        };
        add(icon);
        add(Box.createHorizontalStrut(4));
        add(text = new TreeTextArea());
    }
    
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        String stringValue = tree.convertValueToText(value, isSelected, expanded, leaf, row, hasFocus);
        setEnabled(tree.isEnabled());
        text.setText(stringValue);
        text.setSelect(isSelected);
        text.setFocus(hasFocus);
        if (leaf) {
            icon.setIcon(UIManager.getIcon("Tree.leafIcon"));
        } else if (expanded) {
            icon.setIcon(UIManager.getIcon("Tree.openIcon"));
        } else {
            icon.setIcon(UIManager.getIcon("Tree.closedIcon"));
        }
        return this;
    }

    @Override
    public Dimension getPreferredSize() {
        Dimension iconD = icon.getPreferredSize();
        Dimension textD = text.getPreferredSize();
        int height = iconD.height < textD.height ? textD.height : iconD.height;
        return new Dimension(iconD.width + textD.width, height);
    }

    @Override
    public void setBackground(Color color) {
        if (color instanceof ColorUIResource)
            color = null;
        super.setBackground(color);
    }

    class TreeTextArea extends JTextArea {
        Dimension preferredSize;
        
        TreeTextArea() {
            setLineWrap(true);
            setWrapStyleWord(true);
            setOpaque(true);
        }

        @Override
        public void setBackground(Color color) {
            if (color instanceof ColorUIResource)
            color = null;
            super.setBackground(color);
        }

        @Override
        public void setPreferredSize(Dimension d) {
            if (d != null) {
            preferredSize = d;
            }
        }

        @Override
        public Dimension getPreferredSize() {
            return preferredSize;
        }

        @Override
        public void setText(String str) {
            FontMetrics fm = getToolkit().getFontMetrics(getFont());
            BufferedReader br = new BufferedReader(new StringReader(str));
            String line;
            int maxWidth = 0, lines = 0;
            try {
                while ((line = br.readLine()) != null) {
                    int width = SwingUtilities.computeStringWidth(fm, line);
                    if (maxWidth < width) {
                        maxWidth = width;
                    }
                    lines++;
                }
            } catch (IOException ex) {
                System.out.println(ex);
            }
            lines = (lines < 1) ? 1 : lines;
            int height = fm.getHeight() * lines;
            setPreferredSize(new Dimension(maxWidth + 6, height));
            super.setText(str);
        }

        void setSelect(boolean isSelected) {
            Color bColor;
            if (isSelected) {
                bColor = UIManager.getColor("Tree.selectionBackground");
            } else {
                bColor = UIManager.getColor("Tree.textBackground");
            }
            super.setBackground(bColor);
        }

        void setFocus(boolean hasFocus) {
            if (hasFocus) {
                Color lineColor = UIManager.getColor("Tree.selectionBorderColor");
                setBorder(BorderFactory.createLineBorder(lineColor));
            } else {
                setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
            }
        }
    }
}
   
but the two methods in the event of failure in a Windows look and feel, can anyone help with this?

Published by: user8978073 on April 30, 2011 10:24

Published by: user8978073 on April 30, 2011 10:25

Can't check right now, but - afair, windowsLAF sets the rowHeight to a fixed value (16 or 18 or something like that). Consult the setRowHeight and make sure that there<= 0="" to="" indicate="" that="" it="" should="" be="">

Tags: Java

Similar Questions

  • How to connect 2 PC with CPL blocks on windows?

    How to connect 2 PC with CPL blocks on windows?

    original title: CPL problem
    Hello
    Please select your language from the drop-down menu above to post your question in the language of your choice. The forum in which you've posted is for English only. If you can't find your language above, support for additional international sites options are by following the link below:
  • How to remove a shortcut with the command line?

    How to remove a shortcut with the command line?

    How to make a backup of the local users and groups with command line?

    You delete a shortcut, just as you would remove any other file.  A shortcut will end with the extension ".lnk".  So assuming you are trying to remove the shortcut named "Shortcut.lnk" which appears to the user 'Bob's Office, you use the button Delete (del) or 'clear' command by specifying the full path to the file.  (Remember to put filename in quotes if there is a space anywhere in the path or name) as in:

    del "C:\documents and settings\Bob\Desktop\Shortcut.lnk".

    What kind of a backup 'users and groups' you want to do?  If there is a backup of the users and groups as written in the registry, a good registry as C:\WINDOWS\ERUNT backup program that will make the command line.  If you are trying to backup all users and their data as well, then you are better off with a backup program.

    HTH,
    JW

  • I want to upgrade Windows 7 Starter to Windows 7 Prefessional how can I do this with my preffessional of windows 7 DVD

    I want to upgrade Windows 7 Starter to Windows 7 Prefessional how can I do this with my preffessional of windows 7 DVD

    Yes, you are right. Windows Anytime Upgrade can be used to upgrade Windows 7 Starter to Windows 7 Professional. Apart from this, you can use DVD media and perform the upgrade.

    Before the upgrade, Windows 7 Starter must be enabled.
  • How to send the message to the PC on Windows 7 and Windows XP

    Hi Anoop,

    seeing that you're a technical support engineer, maybe you can help me.
    In my workplace, there are 7 PCs connected in lan.
    5 of them have xp and rest 2 have professional win7 on them.
    We need all employees stay in touch all the time, so I decided to try to MSG. EXE in my win7 machine. I edited the registry to 'Allow remote RPC' entry on my machine and other machine win7. then after I tried the following command:
    "msg [account name] / Server: [name of the pc]"message.
    He waited a few moments and error 5 message.
    and yet one thing, all the machines have exactly identical account names & passwords on them.
    Please tell me how to communicate on both xp & win7.
    Kind regards
    Mr. Pratap Singh

    The messaging service has been removed with the release of Windows Vista and is longer supported in recent versions of Windows.

    I suggest that you try a third-party tool called network Chat

    http://download.CNET.com/network-chat/3000-2085_4-10326659.html

  • How access host files to virtual machine, host is Windows Vista and Red Hat Linux virtual machine?

    Please can you let me know them below, thanks, really appreciate your help on this.

    How access host files to virtual machine, host is Windows Vista and Red Hat Linux virtual machine?

    Thank you and best regards,

    Sam

    The RPM of samba must exist in the CD of RHEL itself. in any case, you can use winSCP tool to your windows host.

  • How to build an equation with variables

    I want to solve an equation below shows zero finder vi by the Newton Raphson:

    z a * b * c * exp(-z/a),.

    a, b, and c are variables

    I can build the equation with constant a, b, c, but how do I build it?

    Thank you very much!

    Use the number to the string functions in the palette of string with the antiderivative of string concatenation to create a formula with your values of a, b and c.  Read the detailed help for more information about limitations on the variable names carefully.  'z' is the only variable in your formula for the detector zero.  Example is LV2009.

    Lynn

  • How to build a URL with Checksum in "JAVASCRIPT"?

    Hi all..

    Could someone help me how to construct a URL with "checksum" in javascript?

    With PL/SQL, we can use apex_util.prepare_url to get the url with checksum. How can I make if I build the URL in javascript?

    Please help me with this.

    Thank you

    Hello

    Just an idea, in your javascript code, you can call an ajax function to construct your URL with PL/SQL code and then return the URL and use it in your javascript code.
    I have never tried but maybe works.

    Kind regards
    SDDC

  • How to build the table with all the combinations of a source table?

    Hello

    I have a 2D array that contains the list of the power user-defined settings. The number of PSs (table rows) is not fixed. For example - 3 PSs:

    Stage of Min Max name

    PS1 3.0 3.6 0.3

    PS2 0.9 1.2 0.1

    PS3 1.7 1.9 0.1

    I need to build, from this list, a table of all the combinations as below:

    PS1 PS2 PS3

    3.0 0.9 1.7

    3.0 0.9 1.8

    3.0 0.9 1.9

    3.0 1.0 1.7

    3.0 1.0 1.8

    3.0 1.0 1.9

    3.0 1.1 1.7

    3.0 1.1 1.8

    3.0 1.1 1.9

    3.0 1.2-1.7

    3.0 1.2-1.8

    3.0 1.2-1.9

    3.3 0.9 1.7

    3.3 0.9 1.8

    3.3 0.9 1.9

    3.3 1.0 1.7

    3.3 1.0 1.8

    3.3 1.0 1.9

    3.3 1.1 1.7

    3.3 1.1 1.8

    3.3 1.1 1.9

    3.3 1.2 1.7

    3.3 1.2 1.8

    3.3 1.2 1.9

    3.6 0.9 1.7

    3.6 0.9 1.8

    3.6 0.9 1.9

    3.6 1.0 1.7

    3.6 1.0 1.8

    3.6 1.0 1.9

    3.6 1.1 1.7

    3.6 1.8 1.1

    3.6 1.1 1.9

    3.6 1.2 1.7

    3.6 1.2 1.8

    3.6 1.2 1.9

    How to build this table programmatically?

    (Note also that the number of rows in the source table is not fixed).

    Thanks in advance!

    Hi Berezka,

    using a magic of automatic indexing:

  • How to build the project with library error in adf adf

    Hello

    IM using jdev 11.1.2.3

    in my project I module 2 so we need to build the project with adf dependency libraries...

    Two copies of the way to build the project with trial and error in adf adf

    Timo

  • How to rename multiple files with the extension in windows xp

    How to rename multiple files with extension in windows XP.

    1. If you want to simply rename the extension, open a run window (Windows Logo key + R), type cmd and press ENTER. Using the CD (Change Directory) command, navigate to the folder in question. Now, type ren *.mp3, *.mp4, and press enter (note the two spaces in the command). Note, rename mp3 MP4 is just an example of the command.

    2. If you want to rename files, download the 32-bit version or 64-bit Bulk Rename, here http://www.bulkrenameutility.co.uk/Main_Intro.php

  • How to make a picture with my webcam to use facebook and other Web sites

    Please tell me how to take pictures with my webcam [toshiba laptop sateliteL755] and keep them to use sites like FACEBOOK, SKYPE soceal media!

    Contact support staff who made the webcam.

  • How to separate two buttons with a vertical line

    Hello

    I'm trying to separate the 2 buttons in regions with a vertical line as Button1 . Button2. I intend to use an image of the vertical line for this. I put the image of a vertical line in the images of the workspace. How can I see the line between the buttons. Can I use the new "Image display" item for this purpose. Any input on this would be appreciated.

    Tahnks,
    NAV

    Published by: Navarannan on 07-Sep-2010 05:34

    Yust create a between your buttons display element and put it in the source of this button a pipe:

    |
    

    sign.

    In the attributes of the feature display HTML form elements, you can put

    s tyle="font-weigh t:bold;fon t-size:20px"
    

    or similar, to influence the layout of the sign of the pipe.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
    -------------------------------------------------------------------

  • Problems with the installation of windows updates and reboot the computer

    When you try to restart the computer it freezes on "installation updates.do not turn off computer.". Currently have 20 updates which will not be installed. computer says CCC.exe prevents the computer from restarting and getting error code 80240016 when you try to install the updates

    Restore point:

    Try typing F8 at startup and in the list of Boot selections, select Mode safe using ARROW top to go there > and then press ENTER.

    Try a restore of the system once, to choose a Restore Point prior to your problem...

    Click Start > programs > Accessories > system tools > system restore > choose another time > next > etc.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

     

    If restore work not and you do not have a Vista DVD from Microsoft, do a repair disc to do a Startup Repair:

    Download the ISO on the link provided and make a record of repair time it starts.

    Go to your Bios/Setup, or the Boot Menu at startup and change the Boot order to make the DVD/CD drive 1st in the boot order, then reboot with the disk in the drive.

    At the startup/power on you should see at the bottom of the screen either F2 or DELETE, go to Setup/Bios or F12 for the Boot Menu.

    When you have changed that, insert the Bootable disk you did in the drive and reboot.

    http://www.bleepingcomputer.com/tutorials/tutorial148.html

    Link above shows what the process looks like and a manual, it load the repair options.

    NeoSmart containing the content of the Windows Vista DVD 'Recovery Centre', as we refer to him. It cannot be used to install or reinstall Windows Vista, and is just a Windows PE interface to recovering your PC. Technically, we could re-create this installation with downloadable media media freely from Microsoft (namely the Microsoft WAIK, several gigabyte download); but it is pretty darn decent of Microsoft to present Windows users who might not be able to create such a thing on their own.

    Read all the info on the website on how to create and use:

    http://NeoSmart.net/blog/2008/Windows-Vista-recovery-disc-download/

    ISO Burner: http://www.snapfiles.com/get/active-isoburner.html

    It's a very good Vista startup repair disk.

    You can do a system restart tool, system, etc it restore.

    It is NOT a disc of resettlement.

    And the 32-bit is what normally comes on a computer, unless 64-bit.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    http://support.Microsoft.com/kb/957307

    Error message when you try to install the updates on the Windows Update Web site or the Microsoft Update Web site: "0 x 80240016.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    If the above does not resolve the problem:

    Windows Update Forum:

    It's updated operating system Vista, upgraded installation and activate Forum.

    You will get the best help for any problem of Update/Service Pack in the Windows Update Forum; the link below:

    http://social.answers.Microsoft.com/forums/en-us/vistawu/threads

    When you repost, are kindly Error Codes and exactly what happens when you try to update.

    In this way, you will receive the best help.

    See you soon.

    Mick Murphy - Microsoft partner

  • HP 8500 will be analyzed with a computer running Windows 7 and not for another.

    HP 8500 will be touring with one of my computers running windows 7 and does not scan for another, once connected USB and both running windows 7 family. I reinstalled the drivers on the second computer, nothing is done.

    The error says it can not connect, however the print function works. The HP utility "fix" would also not work.

    The second computer is windows 7 64 bit.

    The solution you provided worked. Thank you. I have it plugged into USB 3.0 causing the computer communicate only not with the scanner. Thank you very much. I really apreciate your help. Have a great day!

Maybe you are looking for