jTree 背景图片.节点颜色

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();
}

}

你可能感兴趣的:(java,swing,F#)