⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.java

📁 在JAVA中如何实现两棵树之间的拖拽功能.
💻 JAVA
字号:
package twotreedrag;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
//import com.borland.jbcl.layout.*;
import com.borland.jbcl.layout.*;



/**
*

Title: JTree之间的拖拽测试


*
Description:通过向从“源树”中拖拽结点在目标树中重新构造一棵树,实现JTree之间的拖拽单向拖拽,这个类测试的类


* @author awaysrain(绝对零度)
*/




public class Demo extends JFrame {
public JPanel contentPane;
public JScrollPane jScrollPane1 = new JScrollPane();
public XYLayout xYLayout1 = new XYLayout();
public DragSourceTree jTree1 = new DragSourceTree();
public JScrollPane jScrollPane2 = new JScrollPane();
public DragTargetTree jTree2 = new DragTargetTree();
public JLabel jLabel1 = new JLabel();
public JLabel jLabel2 = new JLabel();



//Construct the frame
public Demo () {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}



//Component initialization
public void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Demo");
jLabel1.setFont(new java.awt.Font("DialogInput", 0, 16));
jLabel1.setText("源树");
jLabel2.setEnabled(true);
jLabel2.setFont(new java.awt.Font("DialogInput", 0, 16));
jLabel2.setDebugGraphicsOptions(0);
jLabel2.setDoubleBuffered(false);
jLabel2.setVerifyInputWhenFocusTarget(true);
jLabel2.setDisplayedMnemonic('0');
jLabel2.setText("目标树");
jLabel2.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setVerticalTextPosition(javax.swing.SwingConstants.CENTER);
contentPane.add(jLabel1, new XYConstraints(35, 8, 139, 27));
contentPane.add(jLabel2, new XYConstraints(214, 10, 149, 20));
contentPane.add(jScrollPane2, new XYConstraints(211, 31, 159, 231));
contentPane.add(jScrollPane1, new XYConstraints(25, 31, 153, 230));
jScrollPane1.getViewport().add(jTree1, null);
jScrollPane2.getViewport().add(jTree2, null);
}



//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -