🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.gui
Article #7

Re: Moving widgets/resizing frame undoes these

#7
From: Lars Roe
Date: Thu, 10 Sep 1998 00:00
136 lines
4244 bytes
The LayoutManager repositions it. Put:

this.setLayout(null);

inside void comp_mouseDragged(MouseEvent e) or wherever;


jleuschner@expede.net wrote:


> Howdy,
>
>         I have written a simple app in JBuilder that allows me to grab
> a component and move it around on the screen. This part works great,
> but when I resize the frame/window the widgets move back to their
> original location. Can someone explain this to me? I've attached
> the original code.
>
> Thanks,
>
> Jeff
>
> import java.awt.*;
> import java.awt.event.*;
> import borland.jbcl.control.*;
> import borland.jbcl.layout.*;
> import com.f1j.*;
> import com.sun.java.swing.*;
>
> public class frame extends DecoratedFrame
> {
>
>    //Construct the frame
>    JLabel jLabel1 = new JLabel();
>    XYLayout xYLayout1 = new XYLayout();
>    JButton jButton1 = new JButton();
>    java.awt.Point currentPoint;
>    JTabbedPane jTabbedPane1 = new JTabbedPane();
>    JTextArea jTextArea1 = new JTextArea();
>    JTextArea jTextArea2 = new JTextArea();
>    JTextArea jTextArea3 = new JTextArea();
>
>    public frame()
>    {
>       try
>       {
>          jbInit();
>       }
>       catch (Exception e)
>       {
>          e.printStackTrace();
>       }
>    }
> //Component initialization
>
>    private void jbInit() throws Exception
>    {
>       this.setLayout(xYLayout1);
>       this.setSize(new Dimension(507, 448));
>       this.setTitle("Frame Title");
>       jLabel1.setText("jLabel1");
>       addMouseStuff(jLabel1);
>       jButton1.setText("jButton1");
>       jTextArea1.setText("jTextArea1");
>       jTextArea2.setText("jTextArea2");
>       jTextArea3.setText("jTextArea3");
>       addMouseStuff(jButton1);
>
>       this.add(jLabel1, new XYConstraints(0, 117, -1, -1));
>       this.add(jButton1, new XYConstraints(169, 10, -1, -1));
>       this.add(jTabbedPane1, new XYConstraints(78, 165, 357, 218));
>       jTabbedPane1.addTab("jTextArea1", jTextArea1);
>       jTabbedPane1.addTab("jTextArea2", jTextArea2);
>       jTabbedPane1.addTab("jTextArea3", jTextArea3);
>       addMouseStuff(jTabbedPane1);
>    }
>
>    void addMouseStuff(Component comp)
>    {
>          comp.addMouseMotionListener(new
> java.awt.event.MouseMotionAdapter()
>       {
>          public void mouseDragged(MouseEvent e)
>          {
>             comp_mouseDragged(e);
>          }
>       });
>       comp.addMouseListener(new java.awt.event.MouseAdapter()
>       {
>          public void mousePressed(MouseEvent e)
>          {
>             comp_mousePressed(e);
>          }
>          public void mouseReleased(MouseEvent e)
>          {
>             comp_mouseReleased(e);
>          }
>       });
>
>    }
>
>    void comp_mousePressed(MouseEvent e)
>    {
>         currentPoint = e.getPoint();
>    }
>
>    void comp_mouseReleased(MouseEvent e)
>    {
>       currentPoint = null;
>    }
>
>    void comp_mouseDragged(MouseEvent e)
>    {
>       if (currentPoint == null)
>          return;
>
>       java.awt.Point p = e.getPoint();
>       int xChange = p.x - currentPoint.x;
>       int yChange = p.y - currentPoint.y;
>       java.awt.Point lp = e.getComponent().getLocation();
>       lp.x+=xChange;
>       lp.y+=yChange;
>       e.getComponent().setLocation(lp);
>    }
> }
>
>





--
Lars Roe
612-625-7797
roex0029@tc.umn.edu
Technical Details
Message-ID: <35F82915.7E68DDC7@tc.umn.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35f82c61.20727594@news.onramp.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10fd6d,2b611d0c59e99b8a
X-Google-Attributes: gid10fd6d,public
X-Google-Thread: f5619,2b611d0c59e99b8a
X-Google-Attributes: gidf5619,public
X-Google-Thread: ff01d,2b611d0c59e99b8a
X-Google-Attributes: gidff01d,public
From: Lars Roe <roex0029@tc.umn.edu>
Subject: Re: Moving widgets/resizing frame undoes these
Date: 1998/09/10
Message-ID: <35F82915.7E68DDC7@tc.umn.edu>
X-Deja-AN: 389839959
Content-Transfer-Encoding: 7bit
References: <35f82c61.20727594@news.onramp.net>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: UM
Mime-Version: 1.0
Reply-To: Lars.W.Roe-1@tc.umn.edu
Newsgroups: comp.lang.java.gui,borland.public.jbuilder.jbcl,borland.public.jbuilder.applet-issues