Link to home
Start Free TrialLog in
Avatar of sanjay_thakur
sanjay_thakur

asked on

set the border for JSplitPane divider

Hi,

How do I set the border for the JSPlitPane divider

I know that the border of the components placed
in the SplitPane acts as the divider border

But If I just want to set the border for the divider
irrespective of the border of the components

How do I do this?

Please help
Avatar of heyhey_
heyhey_

did you tried following code ?

splitPane.setBorder(null);
Avatar of sanjay_thakur

ASKER

Hi,

I tried it but this wont help me to set a border
just for the divider.

the splitpane has Panels and the divider just takes the
borders set for the panels

There is no specific way to set the border just
for the divider

Please help
> the splitpane has Panels

post some sample code that we can work on (small compilable example please)
Hi
This is a test code

How do I set the border specifically for the divider
without setting the border for the panels
contained in it?

import javax.swing.JFrame;
import javax.swing.*;

import java.awt.BorderLayout;
import java.awt.Dimension;


class Test
{
    // Instance attributes used in this example
    private JPanel topPanel;
    private JPanel bottomPanel;
    private JSplitPane sp;
    private JFrame frame;

    // Constructor of main frame
    public Test()
    {

        try
        {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e)
        {
        }
        finally
        {
        }


        // Set the frame characteristics
        frame = new JFrame();


        // Create a panel to hold all other components
        topPanel = new JPanel();
        topPanel.setLayout(new BorderLayout());

        bottomPanel = new JPanel();
        topPanel.setLayout(new BorderLayout());


        JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, bottomPanel);
        sp.setBorder(null);
        sp.setPreferredSize(new Dimension(500, 500));
        sp.setDividerSize(10);
        //add the components
        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(sp, BorderLayout.CENTER);

        frame.pack();
        frame.show();

    }


    // Main entry point for this example
    public static void main(String args[])
    {
        // Create an instance of the test application
        Test mainFrame = new Test();

    }


}


There is nothing like  "setDividerBorder()" API

What  if I want to have a custom border for the divider?

Thanks

ASKER CERTIFIED SOLUTION
Avatar of heyhey_
heyhey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
another option is to go through all JSplitPane children, find the Divider component and set it's border only.

       Component comps[] = sp.getComponents();
       for (int i = 0; i  < comps.length; i++)
       {
         System.out.println("" + i + " " + comps[i]);
       }
Hi,

This worked fine for me

Thanks