Results 1 to 8 of 8

Thread: Layout Problem

  1. #1
    cloudracer is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Question Layout Problem

    I'm trying to get my layout of my program 18 by 3 but it will only do 2 columns I'm using GridLayout (18,3) byt that doesn't work I've tried changing the PrefferedSize but that didn't work neither help please
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    Java Code:
    import javax.swing.*;
    
    import java.text.DecimalFormat;
    import java.util.Arrays;
    
    /**
       RoutinePanel class
     
    */
    
    public class RoutinePanel extends JPanel
    {
       // Named constants for charges
    	   private final double SOFA_CHARGE = 599.99;
    	   private final double COMPUTER_DESK_CHARGE = 129.99;
    	   private final double COFFEE_TABLE_CHARGE = 40.0;
    	   private final double ARMCHAIR_CHARGE = 229.99;
    	   private final double TV_STAND_CHARGE = 37.0;
    	   private final double CUSHION_CHARGE = 8.0;
    	   private final double BED_CHARGE = 145.0;
    	   private final double MATRESS_CHARGE = 299.0;
    	   private final double DUVET_CHARGE = 24.99;
    	   private final double PILLOW_CHARGE = 9.99;
    	    
    	
       
    	   TextField ComputerDesk;       // Check box for lube job
    	   JTextField Armchair; // Check box for radiator flush
    	   JTextField CoffeeTable;    // Check box for transmission flush
    	   JTextField TvStand;    // Check box for inspection
    	   JTextField Cushion;       // Check box for muffler replacement
    	   JTextField Bed;  // Check box for tire rotation
    	   JTextField Matress ;
    	   JTextField Duvet;
    	   JTextField Pillow;
    	   JLabel SofaLbl;
    	   JTextField Sofa;
    	   private JLabel ArmchairLbl;
    	   private JLabel ComputerDeskLbl;
    	   private JLabel CoffeeTableLbl;
    	   private JLabel TvStandLbl;
    	   private JLabel CushionLbl;
    	   private JLabel BedLbl;
    	   private JLabel MatressLbl;
    	   private JLabel DuvetLbl;
    	   private JLabel PillowLbl;
    	   private Color Colour;
    	   private JButton b;
    	 
    	   
       /**
          Constructor
       */
          
       public RoutinePanel()
       {
          // Create a DecimalFormat object.
          DecimalFormat dollar = new DecimalFormat("#,##0.00");
          
    Sofa = new JTextField("0");
          
          SofaLbl  = new JLabel("Sofa");
          ArmchairLbl = new JLabel("Armchair");
          Armchair = new JTextField("0");
          ComputerDesk = new TextField("0");
          ComputerDeskLbl = new JLabel("Computer Desk");
          CoffeeTable = new JTextField("0");
          CoffeeTableLbl = new JLabel("Coffee Table");
          TvStand = new JTextField ("0");
          TvStandLbl = new JLabel ("TV Stand");
          Cushion = new JTextField ("0");
          CushionLbl = new JLabel ("Cushion");
          Bed = new JTextField ("0");
          BedLbl = new JLabel("0");
          Matress = new JTextField("0");
          MatressLbl = new JLabel("Matress");
          Duvet = new JTextField("0");
          DuvetLbl = new JLabel("Duvet");
          Pillow = new JTextField("0");
          PillowLbl = new JLabel("Pillow");
          b = new JButton("Choose a Colour");
          b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event)
          { Colour = JColorChooser.showDialog(null, "Pick your Colour", Colour);
        if (Colour==null)
        	Colour=(Colour.WHITE);
        		  
          }
          }
         
          );
    
    
      
       
          // Create a GridLayout manager.
          setLayout(new GridLayout(18, 3));
          
          // Create a border.
          setBorder(BorderFactory.createTitledBorder("Routine Services"));
          
         
          add(SofaLbl);
          add(Sofa);
          add(b);
          add(ArmchairLbl);
          add(Armchair);
          add(ComputerDeskLbl);
          add(ComputerDesk);
          add(CoffeeTableLbl);
          add(CoffeeTable);
          add(TvStandLbl);
          add(TvStand);
          add(CushionLbl);
          add(Cushion);
          add(BedLbl);
          add(Bed);
          add(MatressLbl);
          add(Matress);
          add(DuvetLbl);
          add(Duvet);
          add(PillowLbl);
          add(Pillow);
       }
          
        
       
       /**
          The getCharges method calculates the routine charges.
          @return The amount of routine charges.
       */
       
       public double getCharges()
       {
          double charges = 0;
          
           charges = Double.parseDouble(Sofa.getText()) * SOFA_CHARGE
           + Double.parseDouble(ComputerDesk.getText()) * COMPUTER_DESK_CHARGE
           + Double.parseDouble(CoffeeTable.getText()) * COFFEE_TABLE_CHARGE
           + Double.parseDouble(TvStand.getText()) * TV_STAND_CHARGE
           + Double.parseDouble(Cushion.getText()) * CUSHION_CHARGE
           + Double.parseDouble(Bed.getText()) * BED_CHARGE
           + Double.parseDouble(Pillow.getText()) * PILLOW_CHARGE
           + Double.parseDouble(Duvet.getText()) * DUVET_CHARGE
           + Double.parseDouble(Matress.getText()) * MATRESS_CHARGE;
          
     
          return charges;
       }
       
      
       
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,080
    Rep Power
    4

    Default Re: Layout Problem

    Define "doesn't work"?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    cloudracer is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Layout Problem

    well it's displaying the buttons and fields it in two columns instead of the desired 3.

  4. #4
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    364
    Rep Power
    5

    Default Re: Layout Problem

    Are you seeing the buttons at all?
    GridLayout fills in from top to bottom, left to right.

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,080
    Rep Power
    4

    Default Re: Layout Problem

    You have to match the number of cells with the amount of components you display. You have 21 components, so using 73 works.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,017
    Rep Power
    6

    Default Re: Layout Problem

    From the API documentation. "When both the number of rows and the number
    of columns have been set to non-zero values, either by a constructor or by the
    setRows and setColumns methods, the number of columns specified is ignored."

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,080
    Rep Power
    4

    Default Re: Layout Problem

    Quote Originally Posted by jim829 View Post
    From the API documentation. "When both the number of rows and the number
    of columns have been set to non-zero values, either by a constructor or by the
    setRows and setColumns methods, the number of columns specified is ignored."

    Regards,
    Jim
    Thank god I never have to work with these quirky layoutmanagers. Since I started using MigLayout, I never looked back.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,352
    Rep Power
    6

    Default Re: Layout Problem

    Quote Originally Posted by SurfMan View Post
    Thank god I never have to work with these quirky layoutmanagers. Since I started using MigLayout, I never looked back.
    One LayoutManager to rule them all, One LayoutManager to find them; One LayoutManager to bring them all and in the GUI bind them.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Layout problem
    By Flopet17 in forum Advanced Java
    Replies: 12
    Last Post: 04-04-2014, 10:19 AM
  2. GUI Layout Problem
    By Zelaine in forum New To Java
    Replies: 3
    Last Post: 12-31-2013, 08:12 PM
  3. Layout problem
    By bmL in forum Java Applets
    Replies: 3
    Last Post: 06-24-2012, 05:24 AM
  4. Layout Problem
    By kris5228 in forum AWT / Swing
    Replies: 6
    Last Post: 01-09-2012, 10:38 PM
  5. Layout problem
    By miller.bartek in forum AWT / Swing
    Replies: 3
    Last Post: 01-11-2011, 08:50 PM

Tags for this Thread

Posting Permissions

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