9 Replies - 339 Views - Last Post: 31 July 2013 - 09:40 AM Rate Topic: -----

#1 riperator  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 49
  • Joined: 19-May 13

Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 04:09 AM

I need to make an application in swing, it should look like this SCREENSHOT
What would you recommend?
Is This A Good Question/Topic? 0
  • +

Replies To: Suggest Me A Layout Manager For A Swing Project

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 05:56 AM

A combination of BorerLayouts and GridLayouts. Maybe a BoxLayout too but that might not be needed.
Was This Post Helpful? 2
  • +
  • -

#3 riperator  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 49
  • Joined: 19-May 13

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 06:07 AM

Thanks for a reply, I had an idea to crate it with a three panels and flowlayout, however I'm definitely going to try it out with Border and Grid.
Was This Post Helpful? 0
  • +
  • -

#4 riperator  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 49
  • Joined: 19-May 13

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 06:20 AM

I think I'm going to use Box for the right components, so I can get that space between a button and textbox with a Box.createVerticalStrut(HEIGHT)
Was This Post Helpful? 0
  • +
  • -

#5 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 06:26 AM

FlowLayout isn't a terrible suggestion for the things along the bottom. Give it a shot and see what you think.

Your idea with the Box is sound.
Was This Post Helpful? 0
  • +
  • -

#6 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1423
  • View blog
  • Posts: 3,164
  • Joined: 05-April 11

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 06:42 AM

TABLE in BorderLayout.CENTER
Right side in BorderLayout.EAST. Place the components in a BoxLayout
Bottom in BorderLayout.SOUTH. Place the components in a FlowLayout

That should do it :)
Was This Post Helpful? 1
  • +
  • -

#7 riperator  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 49
  • Joined: 19-May 13

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 06:45 AM

Awesome, so should I create 2 more panels for this components which are connected together ?
Was This Post Helpful? 0
  • +
  • -

#8 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 862
  • View blog
  • Posts: 2,650
  • Joined: 29-July 11

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 07:44 AM

A combination of jpanels and Boxes in BorderLayout. I am sure you could tweak it more. If you are smart, you will use a gui designer for this. It's a monumental waste of time doing it by hand. the designer could do it so much faster.

public class Main {
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				
				class MainWindow extends JFrame {
					{
						setTitle("Main Window");
						setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						buildGui();
						pack();
						setVisible(true);
					}
					
					private void buildGui() {
						//Our West Panel.
						/*
						 * We want it about 30px wide.
						 * We can set height to anything, because Borderlayout will size it to what it wants, anyway.
						 */
						JPanel westPanel = new JPanel();
						westPanel.setPreferredSize(new Dimension(30,0));
						
						//Our center Panel.
						JPanel centerPanel = new JPanel();
						centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
						centerPanel.add(new JPanel() {
							{
								setPreferredSize(new Dimension(400,250));
								setBackground(Color.DARK_GRAY);
							}
						});
						
						//The input panel below the table containing a JButton, JLabel, and JtextField, with its components.
						JPanel inputPanel = new JPanel();
						inputPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
						inputPanel.add(new JButton("BUTTON"));
						inputPanel.add(new JLabel("LABEL"));
						inputPanel.add(new JTextField(5));
						
						centerPanel.add(inputPanel);
						
						//Our east Panel.
						JPanel eastPanel = new JPanel();
						Box eastPanelBox = Box.createVerticalBox();
						eastPanelBox.add(new JButton("BUTTON"));
						eastPanelBox.add(Box.createVerticalStrut(15));
						eastPanelBox.add(new JTextField());
						eastPanelBox.add(Box.createVerticalStrut(5));
						eastPanelBox.add(new JButton("CBOX"));
						eastPanelBox.add(Box.createVerticalStrut(5));
						eastPanelBox.add(new JButton("BUTTON"));
						eastPanel.add(eastPanelBox);
						
						//Now we everything to the BorderLayout.
						add(westPanel, BorderLayout.WEST);
						add(centerPanel, BorderLayout.CENTER);
						add(eastPanel, BorderLayout.EAST);
					}
				}//end Mainwindow
				
				new MainWindow();
			}
		});//end SwingUtilities.invokeLater()
		
		new Main();
	}
	
}


Was This Post Helpful? 0
  • +
  • -

#9 riperator  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 49
  • Joined: 19-May 13

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 08:23 AM

View Postfarrell2k, on 31 July 2013 - 07:44 AM, said:

If you are smart, you will use a gui designer for this.

I would like too, but I do not have permission to do so, it means I have to write..

This post has been edited by riperator: 31 July 2013 - 08:25 AM

Was This Post Helpful? 0
  • +
  • -

#10 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1423
  • View blog
  • Posts: 3,164
  • Joined: 05-April 11

Re: Suggest Me A Layout Manager For A Swing Project

Posted 31 July 2013 - 09:40 AM

If you are smart, you will write Swing by hand ;)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1