🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Moving widgets/resizing frame undoes these

#6
From: jleuschner
Date: Thu, 10 Sep 1998 00:00
116 lines
3670 bytes
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);
   }
}
Technical Details
Message-ID: <35f82c61.20727594@news.onramp.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

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