Code for limiting JSplitPane width does not work in Servoy 4

Didn’t test this too well, but it should do the trick in 3.x or 4.x.

	/*
		Using a native JSplitPane swing component in Servoy for greater control over divider location
	
		[*]	Assumes you have a JPanel bean on your form named "bean_104"
		[*]	Assumes you have a Servoy tabpanel on your form named tabs_160
	*/
	
	var splitPane = new Packages.javax.swing.JSplitPane();
	splitPane.topComponent = new Packages.javax.swing.JLabel("Top Component"); // Add a native swing component
	splitPane.bottomComponent = forms.splitPane.elements.tabs_160; // Add a Servoy component
	splitPane.setOrientation(0); // One component on top of the other
	/*
		Sets the location of the divider to a fixed integer value

		For more on the below syntax see:
		http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html#ExplicitMethod
	*/
	splitPane["setDividerLocation(int)"](250); // There is another constructor for setDividerLocation that allows a number type parameter also, but expects a value between 0 and 1 to represent a percent 
	
	// BorderLayout is one of a number of layout managers that could be used here
	var borderLayout = new java.awt.BorderLayout(0,0);	

	forms.splitPane.elements.bean_104.setLayout(borderLayout);
	forms.splitPane.elements.bean_104.setSize(application.getWindowHeight(), application.getWindowWidth()); // This sets the size of our JPanel, Note that the splitPane will auto-size itself to the size of the JPanel
	forms.splitPane.elements.bean_104.add(splitPane,borderLayout.CENTER,0);
	forms.splitPane.elements.bean_104.doLayout();

BTW…it occurred to me that you might also want to set the width of the splitPane component itself and not the divider location (at some point). If that is the case, the code above can help as well. Just set the width of the JPanel bean to whatever width you want the splitPane to be.

Hi All

I still would like to know how to set the minimum and maximum width/height limit of a JSplitPane bean offered within Servoy. JBader offered a possible solution with native swing component. But there should also be a way to do it with the Java Bean JSPlitPane within Servoy Developer, shouldn’t it?

The following code used to work in Servoy 3.5.x but doesn’t work anymore in Servoy Version 4.x.

	// Does not work in Servoy 4.1.x Should be corrected.
		// Limit the minimum and maximum pane width
		var leftMinDim = forms[formName].elements[splitPaneName].leftComponent.getMinimumSize();
		var rightMinDim = forms[formName].elements[splitPaneName].rightComponent.getMinimumSize();
	
		leftMinDim.width = 200;
		rightMinDim.width = 200;
	
		forms[formName].elements[splitPaneName].leftComponent.setMinimumSize(leftMinDim);
		forms[formName].elements[splitPaneName].rightComponent.setMinimumSize(rightMinDim);
	
		//forms[formName].elements[splitPaneName].leftComponent.setMinimumSize(new java.awt.Dimension(220, 125));
		//forms[formName].elements[splitPaneName].rightComponent.setMinimumSize(new java.awt.Dimension(770, 125));

Anyone found a replacing code for the above?

Regards, Robert

The fact that it worked in 3.5 is very odd, it shouldn’t have.

The minimumSize is something you have to apply to the elements that you place inside the JSplitPane bean, not on the bean itself.

As you use tabPanels which do not have the setMinimumsize() fucntion, this way it won’t work.

Only option I see you have is instead of loading the tabPanel directly into the JSplitPane, load the TabPanel into a JPanel, set the minimumsize on the JPanel and then load the JPanel into the JSplitPane.

Paul