可以研究一下 Drag and Drop(DnD) 我前段时间用DnD做过类似的,最近比较忙,还有一些bug没有解决。 据说Java6里又对DnD做了加强,没有研究,具体哪些还不太清楚。
JSplitPane /** @version 1.02 2004-08-22 @author Cay Horstmann */import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.event.*;/** This program demonstrates the split pane component organizer. */ public class SplitPaneTest { public static void main(String[] args) { JFrame frame = new SplitPaneFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }/** This frame consists of two nested split panes to demonstrate planet images and data. */ class SplitPaneFrame extends JFrame { public SplitPaneFrame() { setTitle("SplitPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // set up components for planet names, images, descriptions final JList planetList = new JList(planets); final JLabel planetImage = new JLabel(); final JTextArea planetDescription = new JTextArea(); planetList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { Planet value = (Planet) planetList.getSelectedValue(); // update image and description planetImage.setIcon(value.getImage()); planetDescription.setText(value.getDescription()); } }); // set up split panes JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, planetList, planetImage); innerPane.setContinuousLayout(true); innerPane.setOneTouchExpandable(true); JSplitPane outerPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, innerPane, planetDescription); add(outerPane, BorderLayout.CENTER); } private Planet[] planets = { new Planet("Mercury", 2440, 0), new Planet("Venus", 6052, 0), new Planet("Earth", 6378, 1), new Planet("Mars", 3397, 2), new Planet("Jupiter", 71492, 16), new Planet("Saturn", 60268, 18), new Planet("Uranus", 25559, 17), new Planet("Neptune", 24766, 8), new Planet("Pluto", 1137, 1), }; private static final int DEFAULT_WIDTH = 300; private static final int DEFAULT_HEIGHT = 300; }/** Describes a planet. */ class Planet { /** Constructs a planet. @param n the planet name @param r the planet radius @param m the number of moons */ public Planet(String n, double r, int m) { name = n; radius = r; moons = m; image = new ImageIcon(name + ".gif"); } public String toString() { return name; } /** Gets a description of the planet. @return the description */ public String getDescription() { return "Radius: " + radius + "\nMoons: " + moons + "\n"; } /** Gets an image of the planet. @return the image */ public ImageIcon getImage() { return image; } private String name; private double radius; private int moons; private ImageIcon image; }
怎样的啊..没看出有什么特别..
我前段时间用DnD做过类似的,最近比较忙,还有一些bug没有解决。
据说Java6里又对DnD做了加强,没有研究,具体哪些还不太清楚。
/**
@version 1.02 2004-08-22
@author Cay Horstmann
*/import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;/**
This program demonstrates the split pane component
organizer.
*/
public class SplitPaneTest
{
public static void main(String[] args)
{
JFrame frame = new SplitPaneFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}/**
This frame consists of two nested split panes to demonstrate
planet images and data.
*/
class SplitPaneFrame extends JFrame
{
public SplitPaneFrame()
{
setTitle("SplitPaneTest");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // set up components for planet names, images, descriptions final JList planetList = new JList(planets);
final JLabel planetImage = new JLabel();
final JTextArea planetDescription = new JTextArea(); planetList.addListSelectionListener(new
ListSelectionListener()
{
public void valueChanged(ListSelectionEvent event)
{
Planet value = (Planet) planetList.getSelectedValue(); // update image and description planetImage.setIcon(value.getImage());
planetDescription.setText(value.getDescription());
}
}); // set up split panes JSplitPane innerPane
= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, planetList, planetImage); innerPane.setContinuousLayout(true);
innerPane.setOneTouchExpandable(true); JSplitPane outerPane
= new JSplitPane(JSplitPane.VERTICAL_SPLIT, innerPane, planetDescription); add(outerPane, BorderLayout.CENTER);
} private Planet[] planets =
{
new Planet("Mercury", 2440, 0),
new Planet("Venus", 6052, 0),
new Planet("Earth", 6378, 1),
new Planet("Mars", 3397, 2),
new Planet("Jupiter", 71492, 16),
new Planet("Saturn", 60268, 18),
new Planet("Uranus", 25559, 17),
new Planet("Neptune", 24766, 8),
new Planet("Pluto", 1137, 1),
};
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 300;
}/**
Describes a planet.
*/
class Planet
{
/**
Constructs a planet.
@param n the planet name
@param r the planet radius
@param m the number of moons
*/
public Planet(String n, double r, int m)
{
name = n;
radius = r;
moons = m;
image = new ImageIcon(name + ".gif");
} public String toString()
{
return name;
} /**
Gets a description of the planet.
@return the description
*/
public String getDescription()
{
return "Radius: " + radius + "\nMoons: " + moons + "\n";
} /**
Gets an image of the planet.
@return the image
*/
public ImageIcon getImage()
{
return image;
} private String name;
private double radius;
private int moons;
private ImageIcon image;
}
不过我不希望采用拆分窗口的方式实现,这种方式不能随意拖动窗体。谢谢chenweionline(键盘上的舞者)。
我去找资料看看,不多你有没有相应的资料或源码可以参考?继续讨论...
谢谢carlkkx() ,找的就是这个。