Results 1 to 3 of 3

Thread: Layout Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432

    Layout Help

    Someone help me add a GridBagLayout to my JApplet here is the code i have

    Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class widget  extends JApplet implements ActionListener
    {
      JRadioButton optBlue = new JRadioButton("Blue");
      JRadioButton optRed = new JRadioButton("Red");
      JRadioButton optYellow = new JRadioButton("Yellow");
      JLabel lblTitle = new JLabel(" Widgets ");
      JLabel lblWidgetColor = new JLabel(" Widget Color: ");
      JLabel lblQuantity = new JLabel(" Quantity ");
      JLabel lblName = new JLabel(" Name: ");
      JLabel lblAddress = new JLabel(" Address: ");
      JLabel lblCreditCard = new JLabel(" Credit Card: ");
      JTextField txtName = new JTextField(" John Smith ");
      JTextField txtAddress = new JTextField("                                  ");
      JTextField txtQuantity = new JTextField("0");
      JTextArea txaCurrentPurchase = new JTextArea(10,50);
      JTextArea txaPurchase = new JTextArea(10,50);
      JCheckBox chkEngrave = new JCheckBox(" Engrave");
      JButton btnAddToShoppingCart = new JButton(" Add to Shopping Cart ");
      JButton btnPurchase = new JButton(" Purchase ");
      JPanel pnlApplet = new JPanel();//Panel for Applet
      JPanel pnlMain = new JPanel(); //Panel for Content
      Font  fntMain = new Font("Arial",Font.BOLD,12);
    
      public void init()
      {
        pnlMain.add(DesignLayout());
        pnlApplet.add(pnlMain);
      }
      public void actionPerformed(ActionEvent action)
      {
      }
      public void DesignLayout()
      {
       // Sets the Layout Mangers propertys
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints constraints = new GridBagConstraints();
        setLayout(gridbag);
        constraints.insets = new Insets(5,2,5,2);
        constraints.fill = GridBagConstraints.NONE;
    
        //Adds Label(lblTitle) to 0,0
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        gridbag.setConstraints(lblTitle,constraints);
        lblTitle.setForeground(Color.orange);
        add(lblTitle);
      }
    }
    but that didnt work ?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    pnlMain.add(DesignLayout());

    Since DesignLayout returns void this can't work.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    Ok Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width