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.


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

Results 1 to 2 of 2

Thread: What is the best way to achieve this layout?

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

    Default What is the best way to achieve this layout?


    I'm trying to develop a java program with a layout that resembles the following:


    However, I'm having trouble laying this out by hand (I typically use the NetBeans GUI designer, but I want to do it by hand this time). I've been coding it, but I can't decide which layout manager would be the best to use in this case. I really want to use the GridBagLayout manager, but I'm not sure if it would be best to use in this situation. Here is what I've come up with so far:

    package application;
    public class AppMain {
        public static void main(String args[]) {
            new AppInterface();
    package application;
    import java.awt.*;
    import javax.swing.*;
    public class AppInterface extends JFrame {
        private JPanel mainPanel;
        private JScrollPane tabScrollPane, textBoxScrollPane;
        private JTabbedPane tabPane;
        private JTextPane textBox;
        private GridBagConstraints constraints;
        public AppInterface() {
        private void initComponents() {
            mainPanel = new JPanel(new GridBagLayout());
            textBoxScrollPane = new JScrollPane();
            textBox = new JTextPane();
            constraints = new GridBagConstraints();
            setTitle("Application Interface");
            setSize(900, 800);
            constraints.gridx = 0;
            constraints.gridy = 0;
            constraints.fill = GridBagConstraints.BOTH;
            mainPanel.add(textBoxScrollPane, constraints);

    I'm trying to get two different panels laid out with the GridBagLayout on each one so I can place the tab panel and text box on different panels. I need two panels side-by-side with the one on the left taking only about 25% of the JFrame and the right one taking 75% of the JFrame. Then, I hope to place the tab pane on the left panel and the text box on the right panel.

    I know that JFrames have BoxLayouts as a default layout. How can I layout two panels with the BoxLayout on the JFrame with one taking 25% and the other taking 75% of the space? I think that would be a good place to start, then I can worry about placing the tab pane and text box. Thank you if you can offer any help.

  2. #2
    Senior Member
    Join Date
    Jul 2013
    Thanked 121 Times in 105 Posts

    Default Re: What is the best way to achieve this layout?

    I would suggest you use the BorderLayout with your button pane on the west and your text area in the center.
    This would not give you a 25% / 75% split but would try to show as much of the button pane as necessary (as much as is needed to show all buttons) and give the rest of the space to the text area.

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. Is it possible to achieve the encapsulation without class
    By stut in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 17th, 2013, 01:55 PM
  3. Replies: 1
    Last Post: April 14th, 2011, 07:50 AM
  4. Trying to achieve Movie Style Rolling Credits
    By javanoob123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 10th, 2011, 08:02 PM