当前位置: 技术问答>java相关
怎样消除JTree在展开和合闭时的闪烁?(付代码)
来源: 互联网 发布时间:2015-05-28
本文导语: package test; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import javax.swing.tree.*; public class Applet1 extends Applet { public void init(){ try{ DefaultMutableTreeNode root ...
package test;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Applet1 extends Applet {
public void init(){
try{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
DefaultMutableTreeNode one = new DefaultMutableTreeNode("one");
DefaultMutableTreeNode two = new DefaultMutableTreeNode("two");
DefaultMutableTreeNode three = new DefaultMutableTreeNode("three");
one.add(new DefaultMutableTreeNode("1"));
one.add(new DefaultMutableTreeNode("2"));
one.add(new DefaultMutableTreeNode("3"));
one.add(new DefaultMutableTreeNode("4"));
one.add(new DefaultMutableTreeNode("5"));
one.add(new DefaultMutableTreeNode("6"));
one.add(new DefaultMutableTreeNode("7"));
root.add(one);
root.add(two);
root.add(three);
root.add(new DefaultMutableTreeNode("4"));
root.add(new DefaultMutableTreeNode("5"));
root.add(new DefaultMutableTreeNode("6"));
root.add(new DefaultMutableTreeNode("7"));
root.add(new DefaultMutableTreeNode("8"));
root.add(new DefaultMutableTreeNode("9"));
two.add(new DefaultMutableTreeNode("4"));
two.add(new DefaultMutableTreeNode("5"));
two.add(new DefaultMutableTreeNode("6"));
two.add(new DefaultMutableTreeNode("7"));
two.add(new DefaultMutableTreeNode("8"));
two.add(new DefaultMutableTreeNode("9"));
this.add(new JScrollPane().add(new JTree(new DefaultTreeModel(root))));
}
catch(Exception e) {
e.printStackTrace();
}
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Applet1 extends Applet {
public void init(){
try{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
DefaultMutableTreeNode one = new DefaultMutableTreeNode("one");
DefaultMutableTreeNode two = new DefaultMutableTreeNode("two");
DefaultMutableTreeNode three = new DefaultMutableTreeNode("three");
one.add(new DefaultMutableTreeNode("1"));
one.add(new DefaultMutableTreeNode("2"));
one.add(new DefaultMutableTreeNode("3"));
one.add(new DefaultMutableTreeNode("4"));
one.add(new DefaultMutableTreeNode("5"));
one.add(new DefaultMutableTreeNode("6"));
one.add(new DefaultMutableTreeNode("7"));
root.add(one);
root.add(two);
root.add(three);
root.add(new DefaultMutableTreeNode("4"));
root.add(new DefaultMutableTreeNode("5"));
root.add(new DefaultMutableTreeNode("6"));
root.add(new DefaultMutableTreeNode("7"));
root.add(new DefaultMutableTreeNode("8"));
root.add(new DefaultMutableTreeNode("9"));
two.add(new DefaultMutableTreeNode("4"));
two.add(new DefaultMutableTreeNode("5"));
two.add(new DefaultMutableTreeNode("6"));
two.add(new DefaultMutableTreeNode("7"));
two.add(new DefaultMutableTreeNode("8"));
two.add(new DefaultMutableTreeNode("9"));
this.add(new JScrollPane().add(new JTree(new DefaultTreeModel(root))));
}
catch(Exception e) {
e.printStackTrace();
}
}
}
|
不会再有闪烁了:
/*
*
*
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Applet1 extends Applet {
public void init(){
try{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
DefaultMutableTreeNode one = new DefaultMutableTreeNode("one");
DefaultMutableTreeNode two = new DefaultMutableTreeNode("two");
DefaultMutableTreeNode three = new DefaultMutableTreeNode("three");
one.add(new DefaultMutableTreeNode("1"));
one.add(new DefaultMutableTreeNode("2"));
one.add(new DefaultMutableTreeNode("3"));
one.add(new DefaultMutableTreeNode("4"));
one.add(new DefaultMutableTreeNode("5"));
one.add(new DefaultMutableTreeNode("6"));
one.add(new DefaultMutableTreeNode("7"));
root.add(one);
root.add(two);
root.add(three);
root.add(new DefaultMutableTreeNode("4"));
root.add(new DefaultMutableTreeNode("5"));
root.add(new DefaultMutableTreeNode("6"));
root.add(new DefaultMutableTreeNode("7"));
root.add(new DefaultMutableTreeNode("8"));
root.add(new DefaultMutableTreeNode("9"));
two.add(new DefaultMutableTreeNode("4"));
two.add(new DefaultMutableTreeNode("5"));
two.add(new DefaultMutableTreeNode("6"));
two.add(new DefaultMutableTreeNode("7"));
two.add(new DefaultMutableTreeNode("8"));
two.add(new DefaultMutableTreeNode("9"));
setLayout(new BorderLayout());
JPanel jpanel=new JPanel();
jpanel.add(new JScrollPane().add(new JTree(new DefaultTreeModel(root))));
add(jpanel,BorderLayout.CENTER);
//this.add();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
/*
*
*
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Applet1 extends Applet {
public void init(){
try{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
DefaultMutableTreeNode one = new DefaultMutableTreeNode("one");
DefaultMutableTreeNode two = new DefaultMutableTreeNode("two");
DefaultMutableTreeNode three = new DefaultMutableTreeNode("three");
one.add(new DefaultMutableTreeNode("1"));
one.add(new DefaultMutableTreeNode("2"));
one.add(new DefaultMutableTreeNode("3"));
one.add(new DefaultMutableTreeNode("4"));
one.add(new DefaultMutableTreeNode("5"));
one.add(new DefaultMutableTreeNode("6"));
one.add(new DefaultMutableTreeNode("7"));
root.add(one);
root.add(two);
root.add(three);
root.add(new DefaultMutableTreeNode("4"));
root.add(new DefaultMutableTreeNode("5"));
root.add(new DefaultMutableTreeNode("6"));
root.add(new DefaultMutableTreeNode("7"));
root.add(new DefaultMutableTreeNode("8"));
root.add(new DefaultMutableTreeNode("9"));
two.add(new DefaultMutableTreeNode("4"));
two.add(new DefaultMutableTreeNode("5"));
two.add(new DefaultMutableTreeNode("6"));
two.add(new DefaultMutableTreeNode("7"));
two.add(new DefaultMutableTreeNode("8"));
two.add(new DefaultMutableTreeNode("9"));
setLayout(new BorderLayout());
JPanel jpanel=new JPanel();
jpanel.add(new JScrollPane().add(new JTree(new DefaultTreeModel(root))));
add(jpanel,BorderLayout.CENTER);
//this.add();
}
catch(Exception e) {
e.printStackTrace();
}
}
}