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 3 of 3

Thread: Help creating this layout

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Location
    United States
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help creating this layout

    files.jpg

    I'm trying to create the above layout (CD/DVD burning app). Which layout manager would be best for achieving this layout? I have been looking at Oracle's visual guide to layout managers, but I haven't been able to come up with anything. Which layout would you use if you were designing this?


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Help creating this layout

    Looks like a border layout with one panel in the center and one panel at the bottom.
    The panel in the center contains some kind of grid, perhaps the MigLayout.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Location
    United States
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help creating this layout

    Thanks for the suggestions, Cornix. I ended up just using GridBagLayout to put everything on one panel. However, I'm having trouble getting my arrow buttons to position themselves correctly and be the correct size. I'll post my code below:

    package manager;
     
    import javax.swing.SwingUtilities;
     
    public class Main {
     
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
     
                @Override
                public void run() {
                    new Gui();
     
                }
            });
     
    	}
     
    }
     
    package manager;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
     
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.WindowConstants;
    import javax.swing.plaf.basic.BasicArrowButton;
     
    public class Gui extends JFrame {
     
        private GridBagConstraints constraints;
        private JButton burnButton, leftArrowButton, rightArrowButton;
        private JPanel panel;
        private JScrollPane localFilesScrollPane, mediaFilesScrollPane;
        private JTextPane localFilesTextPane, mediaFilesTextPane;
        private JMenuBar menu;
        private JMenu file, edit;
        private JMenuItem exit;
     
        public Gui() {
            initComponents();
            setVisible(true);
        }
     
        private void initComponents() {
            constraints = new GridBagConstraints();
            burnButton = new JButton("Burn");
            leftArrowButton = new BasicArrowButton(BasicArrowButton.WEST);
            rightArrowButton = new BasicArrowButton(BasicArrowButton.EAST);
            panel = new JPanel();
            localFilesScrollPane = new JScrollPane();
            mediaFilesScrollPane = new JScrollPane();
            localFilesTextPane = new JTextPane();
            mediaFilesTextPane = new JTextPane();
            menu = new JMenuBar();
            file = new JMenu("File");
            edit = new JMenu("Edit");
            exit = new JMenuItem("Exit");
     
            menu.add(file);
            menu.add(edit);
            file.add(exit);
     
            panel.setLayout(new GridBagLayout());
     
            setJMenuBar(menu);
     
            localFilesTextPane.setEditable(false);
            mediaFilesTextPane.setEditable(false);
     
            localFilesScrollPane.setViewportView(localFilesTextPane);
            mediaFilesScrollPane.setViewportView(mediaFilesTextPane);
     
            localFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
                    .createTitledBorder(BorderFactory.createLineBorder(Color.black), "Local Files"), 
                        BorderFactory.createEmptyBorder(10, 15, 10, 15)));
     
            mediaFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
                    .createTitledBorder(BorderFactory.createLineBorder(Color.black), "Files on Media"), 
                        BorderFactory.createEmptyBorder(10, 15, 10, 15)));
     
            setSize(1000, 500);
            setTitle("Java Burner");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setLocationRelativeTo(this);
     
            localFilesScrollPane.setPreferredSize(new Dimension(400, 300));
            mediaFilesScrollPane.setPreferredSize(new Dimension(400, 300));
     
            constraints.insets = new Insets(15, 15, 15, 15);
     
            constraints.gridx = 0;
            constraints.gridy = 0;
            constraints.gridheight = 2;
            panel.add(localFilesScrollPane, constraints);
     
            constraints.gridx++;
            constraints.gridheight = 1;
            panel.add(leftArrowButton, constraints);
     
            constraints.gridx++;
            constraints.gridheight = 2;
            panel.add(mediaFilesScrollPane, constraints);
     
            constraints.gridx--;
            constraints.gridy++;
            constraints.gridheight = 1;
            panel.add(rightArrowButton, constraints);
     
            constraints.gridx++;
            constraints.gridy++;
            constraints.anchor = GridBagConstraints.SOUTHEAST;
            panel.add(burnButton, constraints);
     
            add(panel, BorderLayout.CENTER);
        }
     
    }

    If you take a look at it, you'll see that the arrow buttons in the middle of the text panes are way too small. They need to be larger. I also need the top arrow button moved down a little and the bottom arrow button moved up. When I tell the buttons to fill their respective cells, the bottom button fills a large amount of space while the top button doesn't change. I'm not sure how to resize the cells. I would appreciate any help.

    --- Update ---

    So I wasn't able to get the buttons to cooperate on the GridBagLayout, so I created a new panel with a BoxLayout to place the buttons in. It seems to be working better, but I still can't get the buttons to resize properly. Calling setPreferredSize() on the arrow buttons does nothing.

    This is my new code:

    package manager;
     
    import javax.swing.SwingUtilities;
     
    public class Main {
     
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
     
                @Override
                public void run() {
                    new Gui();
     
                }
            });
     
    	}
     
    }
     
    package manager;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.Insets;
     
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.WindowConstants;
    import javax.swing.plaf.basic.BasicArrowButton;
     
    public class Gui extends JFrame {
     
        private GridBagConstraints constraints;
        private JButton burnButton, leftArrowButton, rightArrowButton;
        private JPanel mainPanel, buttonPanel;
        private JScrollPane localFilesScrollPane, mediaFilesScrollPane;
        private JTextPane localFilesTextPane, mediaFilesTextPane;
        private JMenuBar menu;
        private JMenu file, edit;
        private JMenuItem exit;
     
        public Gui() {
            initComponents();
            setVisible(true);
        }
     
        private void initComponents() {
            constraints = new GridBagConstraints();
            burnButton = new JButton("Burn");
            leftArrowButton = new BasicArrowButton(BasicArrowButton.WEST);
            rightArrowButton = new BasicArrowButton(BasicArrowButton.EAST);
            mainPanel = new JPanel();
            buttonPanel = new JPanel();
            localFilesScrollPane = new JScrollPane();
            mediaFilesScrollPane = new JScrollPane();
            localFilesTextPane = new JTextPane();
            mediaFilesTextPane = new JTextPane();
            menu = new JMenuBar();
            file = new JMenu("File");
            edit = new JMenu("Edit");
            exit = new JMenuItem("Exit");
     
            menu.add(file);
            menu.add(edit);
            file.add(exit);
     
            mainPanel.setLayout(new GridBagLayout());
            buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
     
            setJMenuBar(menu);
     
            localFilesTextPane.setEditable(false);
            mediaFilesTextPane.setEditable(false);
     
            localFilesScrollPane.setViewportView(localFilesTextPane);
            mediaFilesScrollPane.setViewportView(mediaFilesTextPane);
     
            localFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
                    .createTitledBorder(BorderFactory.createLineBorder(Color.black), "Local Files"), 
                        BorderFactory.createEmptyBorder(10, 15, 10, 15)));
     
            mediaFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
                    .createTitledBorder(BorderFactory.createLineBorder(Color.black), "Files on Media"), 
                        BorderFactory.createEmptyBorder(10, 15, 10, 15)));
     
            setSize(1000, 450);
            setTitle("Java Burner");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setLocationRelativeTo(this);
     
            localFilesScrollPane.setPreferredSize(new Dimension(400, 300));
            mediaFilesScrollPane.setPreferredSize(new Dimension(400, 300));
     
            buttonPanel.add(Box.createVerticalStrut(80));
            buttonPanel.add(leftArrowButton);
            buttonPanel.add(Box.createVerticalStrut(80));
            buttonPanel.add(rightArrowButton);
     
            constraints.fill = GridBagConstraints.HORIZONTAL;
     
            constraints.gridx = 0;
            constraints.gridy = 0;
            constraints.gridheight = 2;
            constraints.insets = new Insets(0, 0, 0, 20);
            mainPanel.add(localFilesScrollPane, constraints);
     
            constraints.gridx++;
            constraints.insets = new Insets(0, 20, 0, 0);
            mainPanel.add(buttonPanel);
     
            constraints.gridx++;
            constraints.gridheight = 2;
            mainPanel.add(mediaFilesScrollPane, constraints);
     
            constraints.gridy = 2;
            constraints.fill = GridBagConstraints.NONE;
            constraints.anchor = GridBagConstraints.SOUTHEAST;
            constraints.insets = new Insets(20, 5, 10, 5);
            mainPanel.add(burnButton, constraints);
     
            add(mainPanel, BorderLayout.CENTER);
        }
     
    }

    This is very close to what I want. I just need to make the arrow buttons larger. Any help?

Similar Threads

  1. GUI Layout - Does anyone know how to set a layout?
    By mikemontesa in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 20th, 2013, 04:35 PM
  2. Creating table with layout in excel through java code
    By kvangala in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 26th, 2012, 01:07 PM
  3. Creating and implementing class for creating a calendar object
    By kumalh in forum Object Oriented Programming
    Replies: 3
    Last Post: July 29th, 2011, 08:40 AM
  4. Replies: 1
    Last Post: April 14th, 2011, 07:50 AM
  5. Grid bag layout inside grid bag layout
    By kiddkoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2011, 08:07 AM