Thread View: comp.lang.java.gui
3 messages
3 total messages
Started by jleuschner
Thu, 10 Sep 1998 00:00
Moving widgets/resizing frame undoes these
Author: jleuschner
Date: Thu, 10 Sep 1998 00:00
Date: Thu, 10 Sep 1998 00:00
116 lines
3670 bytes
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);
}
}
Re: Moving widgets/resizing frame undoes these
Author: Lars Roe
Date: Thu, 10 Sep 1998 00:00
Date: Thu, 10 Sep 1998 00:00
136 lines
4244 bytes
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
Re: Moving widgets/resizing frame undoes these
Author: jleuschner
Date: Fri, 11 Sep 1998 00:00
Date: Fri, 11 Sep 1998 00:00
149 lines
4591 bytes
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
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads