jTree 背景图片.节点颜色

来源:互联网 时间:1970-01-01

import java.awt.*;import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;

public class Tree
{
public static void main(String[] args)
{
JFrame frame = new JFrame("Table");
frame.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
Window win = e.getWindow();
win.setVisible(false);
win.dispose();
System.exit(0);
}
} );


JTree tree = new JTree()
{
ImageIcon image = new ImageIcon( "F://1.jpg" );

public void paint( Graphics g )
{
// First draw the background image - tiled
Dimension d = getSize();
for( int x = 0; x < d.width; x += image.getIconWidth() )
for( int y = 0; y < d.height; y += image.getIconHeight() )
g.drawImage( image.getImage(), x, y, null, null );
super.paint(g);
}

};

tree.setOpaque( false );
tree.setCellRenderer( new MyCellRenderer() );
JScrollPane sp = new JScrollPane( tree );

frame.getContentPane().add( sp );
frame.pack();
frame.show();
}

}



相关阅读:
Top