• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Moving comonents

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know if there is a way to allow the user of a Java Application to move components like buttons around the screen ?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi dave,
the basic requirement for moving the components is to set the LayoutManager of the container to 'null'.
Then the components can be moved within their container by using Component.setLocation(x, y); or Component.setLocation(Point p)
u will also need to set the size of the component by using Component.setSize(width, height)or Component.setSize(Dimension d)
the size needs to be set coz the location & the size are set to a default 0 if the LayoutManager is null
hope this solves ur problem
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dave Donohoe:
Does anyone know if there is a way to allow the user of a Java Application to move components like buttons around the screen ?


Dear Dave,
Here is a working code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MoveAhead extends Applet implements MouseMotionListener
{
Label lbl = new Label ("Hello World");
public void init()
{
add(lbl);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
public void mouseMoved(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
}
 
kishor patankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Dave,
Here is a sample working code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MoveAhead extends Applet implements MouseMotionListener
{
Label lbl = new Label ("Hello World");
public void init()
{
add(lbl);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
public void mouseMoved(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
}
 
kishor patankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is a code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MoveAhead extends Applet implements MouseMotionListener
{
Label lbl = new Label ("Hello World");
public void init()
{
add(lbl);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
public void mouseMoved(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
}
 
Dave Donohoe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kishor, thats great............
Much Appriciated,
Dave
 
Dave Donohoe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Swapnil - that is exactly what I needed !
D
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic