Swing: How do I add buttons to specific spots on a panel?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Swing: How do I add buttons to specific spots on a panel?

  1. #1
    Join Date
    Feb 2006
    Posts
    1

    Swing: How do I add buttons to specific spots on a panel?

    Hi,

    I currently have a 500 * 500 image which is the background of a JPanel (So I suppose I have a 500 * 500 JPanel, basically).

    I would like to be able to place (20*20) buttons on various places of this image - for instance, add button1 at position (200, 420), then button2 at position (100, 480), etc. Is there a straight forward way to do this?

    Thanks.

  2. #2
    Join Date
    May 2005
    Location
    Ontario, Canada
    Posts
    173
    Code:
    import java.applet.*;
    import java.awt.*;
    
    
     public class DoButton extends Applet {
    
     	Button b1;
    
     	public void init() {
    
     		b1 = new Button("Press Me");
     		add(b1);
     	}
     }
    Try this it might work.

  3. #3
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    Quote Originally Posted by Kinda Electroni
    Code:
    import java.applet.*;
    import java.awt.*;
    
    
     public class DoButton extends Applet {
    
     	Button b1;
    
     	public void init() {
    
     		b1 = new Button("Press Me");
     		add(b1);
     	}
     }
    Try this it might work.
    No. That just adds it to the container. You need to set the location using the setLocation(int, int) or setLocation(Point) method.

    Good luck!

Similar Threads

  1. Replies: 0
    Last Post: 11-19-2002, 10:23 PM
  2. Replies: 0
    Last Post: 11-19-2002, 11:34 AM
  3. Displaying XML Data using .Net Controls
    By Greg Rothlander in forum ASP.NET
    Replies: 1
    Last Post: 11-27-2001, 07:09 PM
  4. How can I split 2 panels horizontally?
    By Patrick Ireland in forum .NET
    Replies: 10
    Last Post: 10-14-2001, 06:55 PM
  5. Replies: 0
    Last Post: 05-30-2001, 02:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center