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 636309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:30:04+00:00 2026-05-13T20:30:04+00:00

I’m looking to create an Outlook style UI in a Java desktop app, with

  • 0

I’m looking to create an Outlook style UI in a Java desktop app, with a list of contexts or nodes in a lefthand pane, and the selected context in a pane on the right. How do I go about this?

I’m looking for a bit more detail than ‘use a JFrame’. A tutorial or walk through would be good, or some skeleton code, or a framework/library that provides this kind of thing out of the box.

Thanks.

Edit

My (edited) code so far:

UIPanel

public class UIPanel extends javax.swing.JPanel {

    private final JSplitPane splitPane;

    public UIPanel() {
        super(new BorderLayout());
        initComponents();

        JPanel contextPnl = new ContextPanel();
        JPanel treePnl = new NodePanel(contextPnl);

        this.splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
          true, new JScrollPane(treePnl), new JScrollPane(contextPnl));

        add(splitPane, BorderLayout.CENTER);

        //not sure I need these?
        splitPane.setVisible(true);
        treePnl.setVisible(true);
        contextPnl.setVisible(true);
}

NodePanel

public class NodePanel extends javax.swing.JPanel {

    JPanel _contextPanel;

    public NodePanel(JPanel contextPanel) {
        initComponents();
        _contextPanel = contextPanel;
        initialise();
    }

    private void initialise(){
        nodeTree.addTreeSelectionListener(getTreeListener());
    }

    private TreeSelectionListener getTreeListener(){
        return new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                               nodeTree.getLastSelectedPathComponent();
            // if nothing is selected
            if (node == null)
                return;

        // get selected node
        Object nodeInfo = node.getUserObject();

        CardLayout layout = (CardLayout) _contextPanel.getLayout();
        //layout.show(_contextPanel, "test"); //show context for selected node

        }
    };
}

ContextPanel

public class ContextPanel extends javax.swing.JPanel {

    JPanel _cards;
    final static String CONTEXT1 = "Context 1";
    final static String CONTEXT2 = "Context 2";
    JPanel _context1;
    JPanel _context2;


    public ContextPanel() {
        initComponents();
        intialiseContexts();
    }

    public void updateContext(String contextName){
        //TODO
    }

    private void intialiseContexts(){
        _context1 = new NodeContext();
        _context2 = new NodeContext();
        _cards = new JPanel(new CardLayout());
        _cards.add(_context1, CONTEXT1);
        _cards.add(_context2, CONTEXT2);
}
  • 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-05-13T20:30:04+00:00Added an answer on May 13, 2026 at 8:30 pm

    The key concept here is to define a JSplitPane as your top-level Component with a horizontal split. The left-hand side of the split pane becomes your “tree” view while the right-side is the context panel.

    The trick is to use CardLayout for your context panel and to register a TreeSelectionListener with the tree panel’s JTree so that whenever a tree node is selected, the CardLayout‘s show method is called in order to update what the context panel is currently showing. You will also need to add the various Components to the context panel in order for this approach to work.

    public class UIPanel extends JPanel {
      private static final String BLANK_CARD = "blank";
      private final JSplitPane splitPane;
    
      public UIPanel() {
        super(new BorderLayout());
    
        JPanel treePnl = createTreePanel();
        JPanel contextPnl = createContextPanel();
    
        this.splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
          true, new JScrollPane(treePnl), new JScrollPane(contextPnl));
    
        add(splitPane, BorderLayout.CENTER);
      }
    }
    

    EDIT: Example Usage

    public class Main {
      public static void main(String[] args) {
        // Kick off code to build and display UI on Event Dispatch Thread.
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            JFrame frame = new JFrame("UIPanel Example");
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
    
            // Add UIPanel to JFrame.  Using CENTER layout means it will occupy all
            // available space.
            frame.add(new UIPanel(), BorderLayout.CENTER);
    
            // Explicitly set frame size.  Could use pack() instead.
            frame.setSize(800, 600);
    
            // Center frame on the primary display.
            frame.setLocationRelativeTo(null);
    
            // Finally make frame visible.
            frame.setVisible(true);
          }
        });
      }
    }
    

    Additional Advice

    • I can see you’ve created separate classes for your NodePanel and ContextPanel. Given the simplicity of these classes and how tightly coupled they are it probably makes more sense to embed all the UI components directly within UIPanel and have utility methods that build the two sub-panels. If you do keep with NodePanel and ContextPanel try to make them package private rather than public.

    • The CardLayout approach works well if you have a small(ish) number of nodes and you know them in advance (and hence can add their corresponding Components to the CardLayout in advance). If not, you should consider your context panel simply using BorderLayout and, whenever you click on a node you simply add the relevant node component to the BorderLayout.CENTER position of the NodePanel and call panel.revalidate() to cause it to perform its layout again. The reason I’ve used CardLayout in the past is that it means my nodes only need to remember one piece of information: The card name. However, now I think of it I don’t see any real disadvantage with this other approach – In fact it’s probably more flexible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.