41300

How to change the color or background color of JSplitPane divider?

Question:

I am trying to the set the background color for the JSplitPane divider. I've written the following code, but it doesn't seem to work.

BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI(); BasicSplitPaneDivider divider = ui.getDivider(); divider.setBackground(Color.decode("#FFFACD"));

I've even tried the suggestion given here <a href="https://stackoverflow.com/questions/2448502/how-to-set-background-color-to-a-divider-in-jsplitpane" rel="nofollow">How to set BackGround color to a divider in JSplitPane</a>

Can someone please point out the mistake or let me know any other approach?

Answer1:

This works for me

BasicSplitPaneDivider divider = (BasicSplitPaneDivider) splitPane.getComponent(2); divider.setBackground(Color.black); divider.setBorder(null);

Answer2:

I searched for many post for changing the divider color of split pane. And i did found the solution for it.

splitPane.setUI(new BasicSplitPaneUI() { public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { public void setBorder(Border b) { } @Override public void paint(Graphics g) { g.setColor(Color.grey); g.fillRect(0, 0, getSize().width, getSize().height); super.paint(g); } }; } }); splitPane.setBorder(null);

With the above code,we can set the color,set the border for the divider too.For more information,refer this <a href="http://shemnon.com/speling/2006/02/flattening-the-jsplitpane-divi.html" rel="nofollow">tutorial</a>

Answer3:

What Look and Feel are you using? The LaF can and often does override what you may set.

This may help <a href="http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/color.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/color.html</a>

Recommend

  • how to redirect all www traffic with htaccess to equal non-www pages
  • how to handle large size of update query in mysql with laravel
  • How to show a specific VC , more like navigate to a stack of VC
  • Back press fragments issue in android
  • Safari PHP form submission -file upload hangs
  • Is a .txt file created in VB different than one I'd randomly create?
  • Best practice for switching iPhone views?
  • Adding independent aspx/asmx pages into DotNetNuke
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • Regarding starting the threads on a condition
  • Unable to send e-mail through Java
  • how do i write assembly code from c#?
  • NUnit 3.0 TestCase const custom object arguments
  • Undefined references when compiling gSOAP client
  • how does System.Web.HttpRequest::PathInfo work?
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • Reading a file into a multidimensional array
  • How to remove a SwiftyJSON element?
  • RxJava debounce by arbitrary value
  • pyodbc doesn't report sql server error
  • NSScanner Loop Question
  • Display java JPanel in a JFrame
  • Create DicomImage from scratch using Dcmtk
  • Android fill_parent issue
  • How to do unit test for HttpContext.Current.Server.MapPath
  • how to adjust image in a panel in Java swing?
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Android screen density dpi vs ppi
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • How would I use PHP exceptions to define a redirect?
  • How to extract text from Word files using C#?
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • need help with bizarre java.net.HttpURLConnection behavior
  • How does Linux kernel interrupt the application?
  • LevelDB C iterator
  • How can i traverse a binary tree from right to left in java?