Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8671451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:57:15+00:00 2026-06-12T18:57:15+00:00

I’m working on a text editor in which the user is free to divide

  • 0

I’m working on a text editor in which the user is free to divide the editor window vertically or horizontally any number of times (ie, into any number of panes). A single window can be divided both vertically and horizontally (for example, 2 rows, one which contains 3 columns, etc). Each pane contains a JTextArea inside a JScrollPane and a status bar.

My approach thus far has been to use nested JSplitPanes. I’ve struggled to arrange the split pane dividers so that the space in the window is divided equally among all the vertically- or horizontally-split panes. I’ve come quite close to getting it right, but I’ve had to resort to using setPreferredSize() in a number of places (Should I avoid the use of set[Preferred|Maximum|Minimum]Size methods in Java Swing?).

I am wondering if it would be easier/better to take a different approach entirely. MultiSplitPane looks tempting…

What would be the best layout/approach for my situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:57:16+00:00Added an answer on June 12, 2026 at 6:57 pm

    I decided to invest some time in learning the MultiSplitPane layout. It looks like a good solution.

    Here is the code I wrote as a test. It’s essentially a simulation of a layout that changes dynamically as the user splits the window in various ways. It’s a bit lengthy, but maybe it will be helpful to someone who is trying to learn MultiSplitPane.

    The end result looks like this:

    enter image description here

    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.util.LinkedList;
    
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    
    import org.jdesktop.swingx.MultiSplitPane;
    import org.jdesktop.swingx.MultiSplitLayout.*;
    
    @SuppressWarnings("serial")
    class MultiSplitPaneTest extends JFrame {
        private final static String sampleText;
    
        static {
            String text = "I'm working on a text editor in which the user is free to divide the editor window vertically or horizontally any number of times (ie, into any number of panes).\n";
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 10; i++) {
                sb.append(text);
            }
            sampleText = sb.toString();
        }
    
        private class MyScrollPane extends JScrollPane {
            public MyScrollPane(final Component view) {
                super(view);
            }
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(1440, 900);
            }
        }
    
        public MultiSplitPaneTest() {
            // The application opens with a window containing a single pane (a single text area).
    
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            Container cp = getContentPane();
            cp.setLayout(new BorderLayout());
    
            JTextArea ta1 = new JTextArea();
            ta1.setText("TEXT AREA 1\n" + sampleText);
    
            MyScrollPane sp1 = new MyScrollPane(ta1);
            sp1.setViewportView(ta1);
    
            cp.add(sp1, BorderLayout.CENTER);
    
            pack();
            setLocationRelativeTo(null);
            setVisible(true);
    
            // -------------------------------------------------
    
            // Let's say the user splits the window horizontally, creating a second pane.
            // We'll simulate that with the following code.
    
            JTextArea ta2 = new JTextArea();
            ta2.setText("TEXT AREA 2\n" + sampleText);
    
            MyScrollPane sp2 = new MyScrollPane(ta2);
            sp2.setViewportView(ta2);
    
            Leaf leaf1 = new Leaf("1");
            Leaf leaf2 = new Leaf("2");
    
            LinkedList<Node> rootChildren = new LinkedList<>();
            rootChildren.add(leaf1);
            rootChildren.add(new Divider());
            rootChildren.add(leaf2);
    
            Split root = new Split();
            root.setRowLayout(true);
            root.setChildren(rootChildren);
    
            MultiSplitPane multiSplitPane = new MultiSplitPane();
            multiSplitPane.getMultiSplitLayout().setModel(root);
    
            multiSplitPane.add(sp1, "1");
            multiSplitPane.add(sp2, "2");
    
            cp.remove(sp1);
            cp.add(multiSplitPane, BorderLayout.CENTER);
    
            // --------------------------------------------------
    
            // Let's say the user splits the window horizontally again, creating a new pane on the very left.
    
            JTextArea ta3 = new JTextArea();
            ta3.setText("TEXT AREA 3\n" + sampleText);
    
            MyScrollPane sp3 = new MyScrollPane(ta3);
            sp3.setViewportView(ta3);
    
            Leaf leaf3 = new Leaf("3");
    
            rootChildren.add(0, leaf3);
            rootChildren.add(1, new Divider());
    
            root.setChildren(rootChildren);
    
            multiSplitPane.add(sp3, "3");
    
            multiSplitPane.revalidate();
    
            // --------------------------------------------------
    
            // Let's say the user decides to remove the center pane (that is, the first pane that we started with).
    
            rootChildren.remove(2); // Remove leaf1.
            rootChildren.remove(2); // Remove the divider following leaf1.
    
            root.setChildren(rootChildren);
    
            multiSplitPane.remove(sp1);
    
            multiSplitPane.revalidate();
    
            // --------------------------------------------------
    
            // Let's say the user creates another pane, this time splitting the pane on the right vertically.
    
            rootChildren.remove(leaf2);
    
            JTextArea ta4 = new JTextArea();
            ta4.setText("TEXT AREA 4\n" + sampleText);
    
            MyScrollPane sp4 = new MyScrollPane(ta4);
            sp4.setViewportView(ta4);
    
            Leaf leaf4 = new Leaf("4");
    
            LinkedList<Node> branchChildren = new LinkedList<>();
            branchChildren.add(leaf2);
            branchChildren.add(new Divider());
            branchChildren.add(leaf4);
    
            Split branch = new Split();
            branch.setRowLayout(false);
            branch.setChildren(branchChildren);
    
            rootChildren.add(branch);
    
            root.setChildren(rootChildren);
    
            multiSplitPane.add(sp4, "4");
    
            multiSplitPane.revalidate();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.