- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we set a background color to JSplitPane in Java?
A JSplitPane is a subclass of JComponent class that allows us to arrange two components side by side horizontally or vertically in a single pane. The display areas of both components can also be adjusted at the runtime by the user. The important methods of JSplitPane are remove(), removeAll(), resetToPreferredSizes() and setDividerLocation(). A JSplitPane can generate a PropertyChangeListener interface. We can set a background color to a JSplitPane by adding two different background colors to two panels first and pass these arguments to JSplitPane constructor.
Example
import javax.swing.*; import java.awt.*; public class JSplitPaneColorTest extends JFrame { private JSplitPane jsp; private JPanel panel1,panel2; public JSplitPaneColorTest() { setTitle("JSplitPane Example"); panel1 = new JPanel(); panel1.setBackground(Color.lightGray); panel2 = new JPanel(); panel2.setBackground(Color.blue); jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, panel2); jsp.setDividerSize(10); jsp.setResizeWeight(0.5); add(jsp); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setSize(400, 275); setVisible(true); } public static void main(String args[]) { new JSplitPaneColorTest(); } }
Output
- Related Articles
- How can we set the background color to a JPanel in Java?
- How can we set the foreground and background color to JComboBox items in Java?
- How can we set the background/foreground color for individual column of a JTable in Java?
- How can we change the background and foreground color of a JTooltip in Java?
- How to set default background color for JTextPane in Java?
- How can we hide left/right pane of a JSplitPane programmatically in Java?
- How to set background color in jQuery?
- How to set background color in HTML?
- How to set background color of a View in iOS App?
- How to set background color of a view in Android App
- How to set the background color of a ttk.Combobox in tkinter?
- How to set the background color of a single tab in a JTabbedPane Container with Java?
- How to change JFrame background color in Java
- How to set a particular color as background to a JavaFX chart?
- How to create a nested JSplitPane in Java?

Advertisements