[小娱乐] 一个能拖动组件、改变组件大小的容器
/*
* JDragpullPane.java
*
* Created on 2007年3月20日, 上午12:31
*/
package javax.swing;
import java.awt.Color;
import java.awt.Component;
import java.awt.Rectangle;
import javax.swing.plaf.metal.MetalInternalFrameUI;
/**
* 一个能拖动组件、改变组件大小的容器
* @author vlinux
*/
public class JDragpullPane extends javax.swing.JDesktopPane {
/** Creates new form BeanForm */
public JDragpullPane() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">
private void initComponents() {
}// </editor-fold>
// 变量声明 - 不进行修改
// 变量声明结束
/**
* 将组件c添加到容器中
* 等效于 add( c, JDesktopPane.DEFAULT_LAYER, true )
*/
public Component add( Component c ) {
add( c, javax.swing.JDesktopPane.DEFAULT_LAYER );
return c;
}
/**
* 将组件C添加到容器中
* 等效于 add( c, o, true );
*/
public void add( Component c, Object o ) {
add( c, o, true );
}
/**
* 将组件C添加到容器中
* 其中 dragable 标明了该组件足否允许被拖动
* 等效于 add( c, o, dragable );
*/
public void add( Component c, Object o, boolean dragable ) {
Rectangle rect = c.getBounds();
ComponentPane comp = ComponentPane.instance( rect, dragable );
comp.add(c);
super.add( comp, o );
}
}
class ComponentPane extends javax.swing.JInternalFrame {
public ComponentPane( Rectangle rect ) {
super();
setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(255, 102, 0)));
setBounds( rect );
setResizable(true);
setVisible( true );
}
public static ComponentPane instance( Rectangle rect, boolean dragable ) {
ComponentPane cp = new ComponentPane( rect );
MetalInternalFrameUI ui = (MetalInternalFrameUI) cp.getUI();
if( dragable ) {
ui.setPalette(true);
} else {
ui.setNorthPane(null);
}
return cp;
}
}
* JDragpullPane.java
*
* Created on 2007年3月20日, 上午12:31
*/
package javax.swing;
import java.awt.Color;
import java.awt.Component;
import java.awt.Rectangle;
import javax.swing.plaf.metal.MetalInternalFrameUI;
/**
* 一个能拖动组件、改变组件大小的容器
* @author vlinux
*/
public class JDragpullPane extends javax.swing.JDesktopPane {
/** Creates new form BeanForm */
public JDragpullPane() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">
private void initComponents() {
}// </editor-fold>
// 变量声明 - 不进行修改
// 变量声明结束
/**
* 将组件c添加到容器中
* 等效于 add( c, JDesktopPane.DEFAULT_LAYER, true )
*/
public Component add( Component c ) {
add( c, javax.swing.JDesktopPane.DEFAULT_LAYER );
return c;
}
/**
* 将组件C添加到容器中
* 等效于 add( c, o, true );
*/
public void add( Component c, Object o ) {
add( c, o, true );
}
/**
* 将组件C添加到容器中
* 其中 dragable 标明了该组件足否允许被拖动
* 等效于 add( c, o, dragable );
*/
public void add( Component c, Object o, boolean dragable ) {
Rectangle rect = c.getBounds();
ComponentPane comp = ComponentPane.instance( rect, dragable );
comp.add(c);
super.add( comp, o );
}
}
class ComponentPane extends javax.swing.JInternalFrame {
public ComponentPane( Rectangle rect ) {
super();
setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(255, 102, 0)));
setBounds( rect );
setResizable(true);
setVisible( true );
}
public static ComponentPane instance( Rectangle rect, boolean dragable ) {
ComponentPane cp = new ComponentPane( rect );
MetalInternalFrameUI ui = (MetalInternalFrameUI) cp.getUI();
if( dragable ) {
ui.setPalette(true);
} else {
ui.setNorthPane(null);
}
return cp;
}
}