Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2071 > unrolled thread

Draggable lables/button o

Started by"Chanchal" <chanchal@THRWHITE.remove-dii-this>
First post2011-04-27 15:37 +0000
Last post2011-04-27 15:37 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.gui


Contents

  Draggable lables/button o "Chanchal" <chanchal@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
    Re: Draggable lables/butt "Jeff Higgins" <jeff.higgins@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000

#2071 — Draggable lables/button o

From"Chanchal" <chanchal@THRWHITE.remove-dii-this>
Date2011-04-27 15:37 +0000
SubjectDraggable lables/button o
Message-ID<1184669883.549286.216310@j4g2000prf.googlegroups.com>
  To: comp.lang.java.gui
Hello All,
in an appliction i'm developing, i need to place jlabels or button on
a frame/panel. when the application is running, i should be able to
drag these jlabels/buttons around. how can this be done. Please advice

Thanks in advance

Chanchal

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#2072 — Re: Draggable lables/butt

From"Jeff Higgins" <jeff.higgins@THRWHITE.remove-dii-this>
Date2011-04-27 15:37 +0000
SubjectRe: Draggable lables/butt
Message-ID<ZO1ni.268$nl4.170@newsfe06.lga>
In reply to#2071
  To: comp.lang.java.gui

Chanchal wrote:
> Hello All,
> in an appliction i'm developing, i need to place jlabels or button on
> a frame/panel. when the application is running, i should be able to
> drag these jlabels/buttons around. how can this be done. Please advice
>

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LabelTest
{
  private JFrame frame;
  private JPanel panel = new JPanel();
  private JLabel label = new JLabel("Label");

  public LabelTest()
  {
    frame = new JFrame("LabelTest");
    frame.setSize(200, 200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    label.addMouseMotionListener(new DragHandler());
    panel.add(label);
    frame.add(panel);
    frame.setVisible(true);
  }

  class DragHandler extends MouseMotionAdapter
  {
    public void mouseDragged(MouseEvent e)
    {
      Component c = e.getComponent();
      c.setLocation(c.getX() + e.getX(), c.getY() + e.getY());
      frame.repaint();
    }
  }

  public static void main(String[] args)
  {
    LabelTest test = new LabelTest();
  }
}

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web