Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Old JTree Update Problem
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 25th February 04:28
daniel frey
External User
 
Posts: 1
Default Old JTree Update Problem



Hi all out there

I want to come back to this dammed old JTree problem which doesn't seem
to be solved correctly. Look at the code at the end, run it an press
the switch button. What you see is that the long text gets abbreviated
with an ellipse (...). The usual solutions hack around by setting the
initial text to the longest one which will ever be displayed. That's
not the kind of solution I try to find. The usual advises are to use
validate(), which - together with invalidate and revalidate - do not
solve the problem.

I've read in one post that the bounds of the nodes are cached and
recalculated only upon value changes of the node. Is there a proper way
to solve this issue? How can this cache be invalidated. Any hints on
the insight of this would be highly appreciated.

Thanks in advance.
Daniel Frey

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Test {
static final String TEXT_1 = " - short";
static final String TEXT_2 = " - a really long text";
static String switchText = TEXT_1;

public static void main(String args[]) {
final JTree t = new JTree();
t.setCellRenderer(new DefaultTreeCellRenderer() {
public Component getTreeCellRendererComponent(
JTree t, Object o, boolean s, boolean e,
boolean l, int r, boolean f) {
final JLabel label = (JLabel)
super.getTreeCellRendererComponent(
t, o, s, e, l, r, f);
label.setText(label.getText() + switchText);
return label;
}
});
final JButton b = new JButton("switch");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
switchText = (switchText == TEXT_1 ? TEXT_2 : TEXT_1);
t.invalidate();
t.validate();
t.revalidate();
t.repaint();
}
});
final JFrame f = new JFrame();
f.getContentPane().add(b, BorderLayout.NORTH);
f.getContentPane().add(new JScrollPane(t),
BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(200, 200);
f.setVisible(true);
}
}
  Reply With Quote


 


Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666