Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Positioning problem HELP!?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Positioning problem HELP!?

    got problem with the positioning of the panels in the panelInput-panel. IT seems that they like to be centered.
    Would really like some help...

    Thanks in advance


    package slutprojekt;
     
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
     
     
    public class mainGUI {
     
    		//Frames
    		private JFrame f = new JFrame("Se Window");
     
    		//Paneler
    		private JPanel panelMain = new JPanel();
    		private JPanel panelLeft = new JPanel();
    		private JPanel panelRight = new JPanel();
    		private JPanel panelInput = new JPanel();
    		private JPanel panelBot = new JPanel();
    		private JPanel panelSök = new JPanel();
    		private JPanel panelLabel = new JPanel();
    		private JPanel panelForms = new JPanel();
    		private JPanel panelSkicka = new JPanel();
    		private JPanel panelVisaTop = new JPanel();
    		private JPanel panelVisaCenter = new JPanel();
    		private JPanel panelSearch = new JPanel();
     
    		//Containers
    		private GridBagConstraints inPut = new GridBagConstraints();
     
    		//Knappar
    		private JButton skickaBtn = new JButton("Skicka");
    		private JButton visaBtn = new JButton("Visa");
    		private JButton sökBtn = new JButton("Sök");
     
    		//Labels
    		private JLabel labelNamn = new JLabel("Namn: ");
    		private JLabel labelArtist = new JLabel("Artist: ");
    		private JLabel labelGenre = new JLabel("Genre: ");
    		private JLabel labelÅr = new JLabel("Year: ");
    		private JLabel showTitle = new JLabel("Inmatad data");
     
    		//Textfields
    		private JTextField fieldNamn = new JTextField(20);
    		private JTextField fieldArtist = new JTextField(20);
    		private JTextField fieldGenre = new JTextField(20);
    		private JTextField fieldÅr = new JTextField(20);
    		private JTextField fieldSearch = new JTextField(20);
     
    		//Textområden
    		private JTextArea MusikOut = new JTextArea();
     
    		//Scrollpanes
    		private JScrollPane scrollVisa = new JScrollPane(MusikOut);
     
    		//Optionpanes
    		private JOptionPane noTextAlert = new JOptionPane("Du måste fylla i fälten innan du skickar");
     
    		//Egna klasser
    		Musik[] musikLista = new Musik[20];
     
    		//Nödvändiga global variabler
    		int antal = 0;
     
    		public mainGUI()
    		{	
    			//LABEL EGENSKAPER
    			labelNamn.setFont(new Font("sanserif",Font.PLAIN, 14));
    			labelArtist.setFont(new Font("sanserif",Font.PLAIN, 14));
    			labelGenre.setFont(new Font("sanserif",Font.PLAIN, 14));
    			labelÅr.setFont(new Font("sanserif",Font.PLAIN, 14));
     
    			//PANELLABEL SETUP
    			panelLabel.setBackground(Color.CYAN);
    			panelLabel.setPreferredSize(new Dimension(100, 300));
    			panelLabel.setLayout(new GridLayout(4,1));
    			panelLabel.add(labelNamn);
    			panelLabel.add(labelArtist);
    			panelLabel.add(labelGenre);
    			panelLabel.add(labelÅr);
     
    			//PANELFORMS SETUP
    			panelForms.setBackground(Color.green);
    			panelForms.setPreferredSize(new Dimension(300, 300));
    			panelForms.setLayout(new GridLayout(4,1));
    			panelForms.add(fieldNamn);
    			panelForms.add(fieldArtist);
    			panelForms.add(fieldGenre);
    			panelForms.add(fieldÅr);
     
    			//PANELSÖK SETUP
    			panelSök.setBackground(Color.GRAY);
    			panelSök.setPreferredSize(new Dimension(400, 175));
     
    			//PANELINPUT SETUP
    			panelInput.setBackground(Color.RED);
    			panelInput.setPreferredSize(new Dimension(400, 425));
    			panelInput.add(panelLabel);
    			panelInput.add(panelForms);
    			//panelInput.add(panelBot, BorderLayout.SOUTH);
    			//panelInput.setBounds(0, 0, 550, 400);
     
    			//PANELLEFT SETUP
    			panelLeft.setBackground(Color.GREEN);
    			panelLeft.add(panelInput, BorderLayout.NORTH);
    			panelLeft.add(panelSök, BorderLayout.SOUTH);
     
    			//PANELRIGHT SETUP
    			panelRight.setBackground(Color.BLUE);
     
    			//PANELMAIN SETUP
    			panelMain.setLayout(new GridLayout(1, 2));
    			panelMain.add(panelLeft);
    			panelMain.add(panelRight);
     
    			//MAINGUI SETUP
    			f.getContentPane().add(panelMain);
     
    		}
     
    		public void körFrame()
    		{
    			f.setPreferredSize(new Dimension(800, 600));
    			f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    			f.pack();
    			f.setVisible(true);
    		} 
     
    		public static void main(String[] args) 
    		{
    			SwingUtilities.invokeLater(new Runnable() {
    	            public void run() {
    	            	mainGUI GUI = new mainGUI();
    	        		GUI.körFrame();
    	            }
    	        });
    		}
     
    }
    Last edited by R4DiCaL; May 6th, 2012 at 08:28 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Positioning problem HELP!?

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Positioning problem HELP!?

    there you go

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Positioning problem HELP!?

    Can you explain what the problem is? What do you want the program to do?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Positioning problem HELP!?

    my problem is that when i add panelLabel and panelForms to panelInput they position themselves in the center of the panel. I can't make them move to the sides like a want to...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Positioning problem HELP!?

    You need to try using layout managers for the panels. You are giving the current layout manager instructions that it is not using:
    panelInput.add(pnlInpLeft, BorderLayout.WEST);

    panelInput is not using a BorderLayout so that is ignored. Try setting its layout manager to BorderLayout.
    Last edited by Norm; May 6th, 2012 at 10:46 AM. Reason: spelling
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Positioning problem HELP!?

    I don't really understand... I would like if the cyan box could go into the left top corner instead of in the center.
    probForum.jpg

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Positioning problem HELP!?

    Did you change the layout manager as I suggested?
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    R4DiCaL (May 6th, 2012)

  10. #9
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Positioning problem HELP!?

    oh didn't understand what to change at first but now i've changed it and it worked
    Thanks a lot mate

Similar Threads

  1. [SOLVED] Positioning/Resizing JList Help
    By KILL3RTACO in forum AWT / Java Swing
    Replies: 2
    Last Post: October 3rd, 2011, 01:00 PM
  2. button positioning
    By pds8475 in forum Java Theory & Questions
    Replies: 1
    Last Post: January 29th, 2011, 09:35 AM
  3. Positioning elements. Is it possible without layouts?
    By goodguy in forum AWT / Java Swing
    Replies: 6
    Last Post: January 21st, 2011, 02:24 PM
  4. The positioning and alignment of the text on the paper to be printed
    By java_fledgeling in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 8th, 2010, 08:54 PM
  5. Content positioning on the screen
    By Drakenmul in forum AWT / Java Swing
    Replies: 1
    Last Post: July 27th, 2009, 09:02 AM