In this tutorials, we are going to implement a simple Java project using Swing JSplitPane and JList.

Swing JSplitPane :
package com.swing.examples;

import java.awt.Container;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class SplitPaneDemo extends JFrame {

    JSplitPane splitPane, mainSplitPane;
    JList list;
    JPanel listPanel, imagePanel;
    JLabel img;
    Container contentPane;
    String listData[] = {"duke","duke.running","duke2","dukeMagnify","dukeplug","dukeSnooze","dukeWave","dukeWaveRed","cow"};
    JTextArea textArea;
        super("SplitPane Demo !");
        list = new JList(listData);
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {    
                textArea.setText("This is : "+list.getSelectedValue());
                //Local Images path
                img.setIcon(new ImageIcon("C:\\images\\"+list.getSelectedValue()+".gif"));
        textArea = new JTextArea(4,30);
        // Adding ListPanel
        listPanel = new JPanel();
        // Adding Image Pannel
        img = new JLabel();
        imagePanel = new JPanel();
        // Creating SplitPanel
        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false,new JScrollPane(listPanel),imagePanel);
        mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,splitPane,new JScrollPane(textArea));
        contentPane = getContentPane();
        setSize(400, 275);
    public static void main(String[] args) {
        new SplitPaneDemo();


Output :

Spring JSplitPane Example

Selecting the JList and performing an action.

Spring JSplitPane Example 2

Happy Learning 🙂

About the Author:

Founder of Love Java, Python, Shell and opensource frameworks. Follow him on twitter and facebook for latest updates.

Leave A Comment