Swing/ResizableComponents のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/ResizableComponents へ行く。
- 1 (2008-05-19 (月) 13:41:14)
- 2 (2011-05-28 (土) 01:33:39)
- 3 (2014-11-09 (日) 02:40:46)
- 4 (2015-02-26 (木) 13:58:00)
- 5 (2016-11-22 (火) 21:03:43)
- 6 (2017-11-26 (日) 23:48:30)
- 7 (2018-09-18 (火) 18:46:09)
- 8 (2019-02-21 (木) 14:38:03)
- 9 (2019-05-22 (水) 19:35:38)
- 10 (2019-05-23 (木) 15:52:44)
- 11 (2021-02-17 (水) 08:19:22)
- 12 (2022-10-07 (金) 15:00:53)
- 13 (2024-02-03 (土) 13:54:45)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JComponentの移動、リサイズ #navi(../) *JComponentの移動、リサイズ [#v450b08b] Posted by [[terai]] at 2008-05-19 #contents **概要 [#af02f69f] JLayeredPaneに、移動、リサイズ可なコンポーネントを追加します。 -&jnlp; -&jar; -&zip; #screenshot **サンプルコード [#n84bb09d] #code{{ public void mouseDragged(MouseEvent e) { if(startPos==null || startingBounds==null) return; Point p = SwingUtilities.convertPoint((Component)e.getSource(), e.getX(), e.getY(), null); int deltaX = startPos.x - p.x; int deltaY = startPos.y - p.y; int newX = getX(); int newY = getY(); int newW = getWidth(); int newH = getHeight(); JComponent parent = (JComponent)getParent(); Rectangle parentBounds = parent.getBounds(); Dimension min = new Dimension(50,50); Dimension max = new Dimension(500,500); switch(cursor) { case Cursor.N_RESIZE_CURSOR: { if(startingBounds.height + deltaY < min.height) { deltaY = -(startingBounds.height - min.height); }else if(startingBounds.height + deltaY > max.height) { deltaY = max.height - startingBounds.height; } if(startingBounds.y - deltaY < 0) { deltaY = startingBounds.y; } newX = startingBounds.x; newY = startingBounds.y - deltaY; newW = startingBounds.width; newH = startingBounds.height + deltaY; break; } case Cursor.NE_RESIZE_CURSOR: { if(startingBounds.height + deltaY < min.height) { deltaY = -(startingBounds.height - min.height); //...... }} **解説 [#sc16de97] 上記のサンプルでは、ツールバーやポップアップメニューから、移動、リサイズ可能なJTableやJTreeを追加することができます。 リサイズボーダーの描画などは、[[Resizable Components - Santhosh Kumar's Weblog>http://www.jroller.com/santhosh/entry/resizable_components]]から、マウスのドラッグによる移動、リサイズの最大値、最小値の制限などは、%JAVA_HOME%/src/javax/swing/plaf/basic/BasicInternalFrameUI.java からの引用です。 ---- JDK1.5では、JLayeredPane#setComponentPopupMenuを使う場合、以下のようにダミーのマウスリスナーなどを追加しておく必要があります。 #code{{ layer.setComponentPopupMenu(new MyPopupMenu()); layer.addMouseListener(new MouseAdapter() {}); }} **参考リンク [#qf2f4f0c] -[[Resizable Components - Santhosh Kumar's Weblog>http://www.jroller.com/santhosh/entry/resizable_components]] **コメント [#r6bdc669] #comment