package ff;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
@SuppressWarnings("serial")
public class TextFrame extends JFrame{
private JSplitPane jSplitPane=new JSplitPane();//窗體分割線
private JScrollPane jRightScrollPane=new JScrollPane();//右邊切換panel
private JScrollPane jLeftScrollPane=new JScrollPane();//左邊放主Tree
private JLabel jlRightDef= new JLabel();//右邊預設介面
public TextFrame()
{
jSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
jSplitPane.setDividerLocation(170);//左邊大小
jSplitPane.setLeftComponent(jLeftScrollPane);
jSplitPane.setRightComponent(jRightScrollPane);
initMainJTree();
this.add(jSplitPane);
this.setSize(400,500);
this.setLocation(200,100);
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
}
//初始化功能樹
private void initMainJTree()
JTree jTree=new JTree();
jLeftScrollPane.setViewportView(new JPanel().add(jTree));
jTree.setEditable(false);
jTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath treePath=e.getNewLeadSelectionPath();//獲得根節點到選著節點的路徑
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
jlRightDef.setText(node.toString());
jRightScrollPane.setViewportView(jlRightDef);
});
public static void main(String[]args)
try {//windows風格
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
new TextFrame();
package ff;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
@SuppressWarnings("serial")
public class TextFrame extends JFrame{
private JSplitPane jSplitPane=new JSplitPane();//窗體分割線
private JScrollPane jRightScrollPane=new JScrollPane();//右邊切換panel
private JScrollPane jLeftScrollPane=new JScrollPane();//左邊放主Tree
private JLabel jlRightDef= new JLabel();//右邊預設介面
public TextFrame()
{
jSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
jSplitPane.setDividerLocation(170);//左邊大小
jSplitPane.setLeftComponent(jLeftScrollPane);
jSplitPane.setRightComponent(jRightScrollPane);
initMainJTree();
this.add(jSplitPane);
this.setSize(400,500);
this.setLocation(200,100);
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
}
//初始化功能樹
private void initMainJTree()
{
JTree jTree=new JTree();
jLeftScrollPane.setViewportView(new JPanel().add(jTree));
jTree.setEditable(false);
jTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath treePath=e.getNewLeadSelectionPath();//獲得根節點到選著節點的路徑
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
jlRightDef.setText(node.toString());
jRightScrollPane.setViewportView(jlRightDef);
}
});
}
public static void main(String[]args)
{
try {//windows風格
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
new TextFrame();
}
}