📄 demotree.java
字号:
one.add(two);
two = new MyNode("Custom 3D", false);
two.setButton(1, false);
one.add(two);
pv.jfcx.PVNode three = new pv.jfcx.PVNode("Check 1");
three.setButton(1, true);
two.add(three);
three = new pv.jfcx.PVNode("Disabled");
three.setButton(1, false);
three.getButton().setEnabled(false);
two.add(three);
two = new pv.jfcx.PVNode("Check 3");
two.setButton(1, false);
one.add(two);
two = new pv.jfcx.PVNode("Radio on");
two.setButton(2, true);
one.add(two);
two = new pv.jfcx.PVNode("Radio off");
two.setButton(2, false);
one.add(two);
one.add(new pv.jfcx.PVNode("Normal"));
three = new pv.jfcx.PVNode("Radio 1");
three.setButton(2, false);
two.add(three);
three = new pv.jfcx.PVNode("Radio 2");
three.setButton(2, true);
two.add(three);
three = new pv.jfcx.PVNode("Disabled");
three.setButton(2, false);
three.getButton().setEnabled(false);
two.add(three);
three = new pv.jfcx.PVNode("Radio 4");
three.setButton(2, false);
two.add(three);
root.add(one);
one = new pv.jfcx.PVNode("One");
one.setImageAt(new ImageIcon("e:/Tree/Images/ballon.gif"),
pv.jfcx.JPVTree.CLOSED);
one.setImageAt(new ImageIcon("e:/Tree/Images/task.gif"),
pv.jfcx.JPVTree.CLOSED_SEL);
Icon im = new ImageIcon("e:/Tree/Images/bell.gif");
one.setImageAt(im, pv.jfcx.JPVTree.OPENED);
one.setImageAt(im, pv.jfcx.JPVTree.OPENED_SEL);
two = new pv.jfcx.PVNode("Courier20, h30");
two.setFont(new Font("Courier", 0, 20));
two.setHeight(30);
one.add(two);
root.add(one);
three = new pv.jfcx.PVNode("NASDAQ");
one.setFont(new Font("SansSerif", 0, 16));
two.add(three);
three = new pv.jfcx.PVNode("NYSE");
three.setForeground(Color.red);
int i = 0;
while(i++ < 10)
three.add(new pv.jfcx.PVNode("Bonds" + i));
two.add(three);
three = new pv.jfcx.PVNode("h30");
three.setHeight(30);
two.add(three);
one.add(two);
two = new pv.jfcx.PVNode("Courier25, h15");
two.setHeight(15);
two.setFont(new Font("Courier", 0, 25));
one.add(two);
two = new pv.jfcx.PVNode("Arial18, h30");
two.setHeight(30);
two.setFont(new Font("Arial", 0, 18));
two.setForeground(Color.pink);
one.add(two);
two = new pv.jfcx.PVNode("Not Editable");
two.setEditableTreeLabel(false);
one.add(two);
root.add(one);
one = new pv.jfcx.PVNode("Courier");
one.setFont(new Font("Courier", 0, 10));
one.setImageAt(im, pv.jfcx.JPVTree.CLOSED);
root.add(one);
one = new pv.jfcx.PVNode("Not Editable");
one.setEditableTreeLabel(false);
one.setImageAt(im, pv.jfcx.JPVTree.CLOSED_SEL);
im = new ImageIcon("e:/Tree/Images/cdrom.gif");
one.setImageAt(im, pv.jfcx.JPVTree.CLOSED);
root.add(one);
one = new pv.jfcx.PVNode("Courier Red, h25");
one.setHeight(25);
one.setFont(new Font("Courier", 0, 10));
one.setForeground(Color.red);
root.add(one);
one = new pv.jfcx.PVNode("Gray");
one.setForeground(Color.gray);
one.setImageAt(im, pv.jfcx.JPVTree.CLOSED);
root.add(one);
one = new pv.jfcx.PVNode("Blue, h40");
one.setBackground(Color.blue);
one.setForeground(Color.red);
one.add(new pv.jfcx.PVNode("Nasdaq"));
one.add(new pv.jfcx.PVNode("Nasdaq-100"));
root.add(one);
root.add(new pv.jfcx.PVNode("Editorial"));
two = new pv.jfcx.PVNode("Market News");
two.setHeight(40);
two.setBackground(Color.pink);
root.add(two);
root.add(new pv.jfcx.PVNode("Market News"));
root.add(new pv.jfcx.PVNode("Investor Services"));
//--------------------------
// example of listener to the "mousePressed" event
/*
tree.getTree().addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
pv.jfcx.JPVTree t = (pv.jfcx.JPVTree)e.getSource();
TreePath path = t.getPathForLocation(e.getX(), e.getY());
if(path != null)
{
pv.jfcx.PVNode node = (pv.jfcx.PVNode)path.getLastPathComponent();
Rectangle r = t.getPathBounds(path);
}
}
});
*/
return tree;
}
//----------------------
// example to customize painting of checkbox images
class MyNode extends pv.jfcx.PVNode
{
//-----------
// optional appearance
boolean m_flat;
//-----------
// constructor
public MyNode(Object o, boolean flat)
{ super(o); m_flat = flat; }
//-----------
// optional adjustment for extra icon
public int getIconWidth()
{
Icon im = getExtraIcon();
return (im == null) ? 13 : 15 + im.getIconWidth();
}
//-----------
// optional adjustment for extra icon
// public int getIconHeight()
// {
// Icon im = getExtraIcon();
// return Math.max((im == null) ? 13 : im.getIconHeight(), 13);
// }
//-----------
// optional painting extra icon
Icon getExtraIcon()
{ return (m_icons == null) ? null : m_icons[0]; }
//-----------
// paint custom checkbox and extra icon
public void paintIcon(Component c, Graphics g, int x, int y)
{
pv.util.PVImage.checkbox(g, Color.cyan, x, y, isChecked(), m_flat);
Icon im = getExtraIcon();
if(im != null)
im.paintIcon(c, g, x + 15, y);
}
}
//-------------------
void init0()
{
pack();
setBounds(1, 5, 710, 430);
setVisible(true);
}
//----------------------------
/*
// process radio button events
void doRadio(Object src)
{
String look = "javax.swing.plaf.metal.MetalLookAndFeel";
if(src == m_look[1])
look = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
if(src == m_look[2])
look = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try
{
UIManager.setLookAndFeel(look);
SwingUtilities.updateComponentTreeUI(this);
init0();
}catch(Exception e){}
}
*/
//-------------------
/* // example to set initial selection when setLAF_Images(false)
boolean m_once = true;
public void paint(Graphics g)
{
super.paint(g);
if(m_once)
m_tree.getTree().setSelectionRow(1);
m_once = false;
}
*/
//--------------------
public static void main(String[] args)
{ new DemoTree(); }
/*
//--------------------
// example to customize painting of node(s).
class MyTree extends pv.jfcx.JPVTree
{
public void setCellRenderer(TreeCellRenderer r)
{
if(!(r instanceof MyRenderer))
r = new MyRenderer();
super.setCellRenderer(r);
}
public class MyRenderer extends Renderer
{
public void paint(Graphics g)
{
super.paint(g);
// g.setColor(Color.red);
// g.fillOval(30, 0, 60, 15);
}
public Component getTreeCellRendererComponent(
JTree tree, Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus)
{
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
// hide expanded image
if(expanded) setIcon(null);
return this;
}
}
}
//*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -