Adding buttons to Frame


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Adding buttons to Frame

  1. #1
    Join Date
    Sep 2004
    Posts
    59

    Adding buttons to Frame

    Ive a question, how can i add 3 JButton's to a frame?


    example:
    [code]

    public BlasterFrame(String title) {
    super (title, true, true, true, true);

    JButton jb = new JButton("ok");
    Container c = getContentPane();
    //c.add(jb);

    c.add(jt, BorderLayout.CENTER);
    c.add(img1, BorderLayout.WEST);

    ButtonGroup bg = new ButtonGroup();
    c.add(jbNext, BorderLayout.SOUTH);
    // c.add(jbPrevious, BorderLayout.SOUTH);
    // c.add(jbClose, BorderLayout.SOUTH);

    setSize(200,300);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }




    thank you
    My own java video tutorials, feel free to watch it.
    http://www.engineeringserver.com/for...amming-b311.0/ Need java help? For beginning and intermediate java coders!

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You do that by adding a JPanel to the frames contentPane, say ctrlPanel, then
    you set that panels Layoutmanager to something suitable (FlowLayout, GridLayout...)
    and add your buttons to that panel, big deal

    Note: JPanels and JButtons are all Components, but the JPanels are also
    Containers. As "addable objects" they are all Components.
    Last edited by sjalle; 06-19-2005 at 08:55 AM.
    eschew obfuscation

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