🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Moving widgets/resizing frame undoes these

#8
From: jleuschner
Date: Fri, 11 Sep 1998 00:00
149 lines
4591 bytes
Can you explain this to me? I thought all panels required the layout?
I noticed that I get errors if I don't start out with a layout?
Also, why doesn't the original work?

Thanks,

Jeff

On Thu, 10 Sep 1998 14:31:33 -0500, Lars Roe <roex0029@tc.umn.edu>
wrote:

>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: <35f97f32.15247004@news.onramp.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35f82c61.20727594@news.onramp.net> <35F82915.7E68DDC7@tc.umn.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5619,2b611d0c59e99b8a
X-Google-Attributes: gidf5619,public
X-Google-Thread: ff01d,2b611d0c59e99b8a
X-Google-Attributes: gidff01d,public
X-Google-Thread: 10fd6d,2b611d0c59e99b8a
X-Google-Attributes: gid10fd6d,public
From: jleuschner@expede.net
Subject: Re: Moving widgets/resizing frame undoes these
Date: 1998/09/11
Message-ID: <35f97f32.15247004@news.onramp.net>
X-Deja-AN: 390186016
Sender: expede9@209.176.50.66
References: <35f82c61.20727594@news.onramp.net> <35F82915.7E68DDC7@tc.umn.edu>
Organization: OnRamp, http://www.onramp.net/
Newsgroups: comp.lang.java.gui,borland.public.jbuilder.jbcl,borland.public.jbuilder.applet-issues