Java Swing JSplitPane Example

By |2018-10-27T09:06:02+05:30October 31st, 2017|java|

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:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment