当前位置: 代码迷 >> Java相关 >> [小娱乐] 一个能拖动组件、改变组件大小的容器
  详细解决方案

[小娱乐] 一个能拖动组件、改变组件大小的容器

热度:110   发布时间:2007-03-20 01:48:02.0
[小娱乐] 一个能拖动组件、改变组件大小的容器
/*
* 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;
}

}

搜索更多相关的解决方案: 拖动组件  组件大小  容器  import  awt  

----------------解决方案--------------------------------------------------------
回复:(神vLinux飘飘)[小娱乐] 一个能拖动组件、改...
一个DEMO
/*
* DragpullDemo.java
*
* Created on 2007年3月20日, 上午1:50
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package examples.javax.swing;

import javax.swing.JDragpullPane;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;

/**
*
* @author vlinux
*/
public class DragpullDemo extends JFrame {

/**
* Creates a new instance of DragpullDemo
*/
public DragpullDemo() {
JDragpullPane pane = new JDragpullPane();
this.getRootPane().setContentPane( pane );

JTextArea textArea = new JTextArea(20,50);
textArea.setBounds(10,20,30,40);

JTable table = new JTable();
table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
table.setBounds(30,30,70,150);

pane.add( textArea );
pane.add( table );


setBounds(100,200,300,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}


public static void main(String... args) {
new DragpullDemo();
}

}


----------------解决方案--------------------------------------------------------

----------------解决方案--------------------------------------------------------
无聊,还是帮你顶一下吧~~
----------------解决方案--------------------------------------------------------
本来就不指望你明白~~哎~~~~
----------------解决方案--------------------------------------------------------
晕,怎么又做起斑竹来啦,看来大家还是冥顽不灵啊,看来又要发贴了~~
----------------解决方案--------------------------------------------------------
  相关解决方案