-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.1
-
sparc
-
solaris_2.6
JSplitPane.getMaximumDividerLocation() returns incorrect size. Initialy it is off by 10 pixels. If the user moves the SplitPane then the size gets adjusted correctly. This is done through the method call startDragging() in BasicSplitPaneUI.java source.
getMaximumDividerLocation initially returns incorrect value because it is dependant on dividerSize to be correct, initially dividerSize is set to 0.
Side Note: Test was run on a Sparc with OpenWindows. CDE will return a different size based on inset sizes.
Value from Source code
BasicSplitPaneDivider.java
/**
* Size of the divider.
*/
protected int dividerSize = 0; // default - SET TO 0???
From source Code
BasicSplitPaneUI.java
public int getMaximumDividerLocation(JSplitPane jc) {
maxLoc -= (dividerSize + getDividerBorderSize());
dividerSize does not get set correctly until user tries to start
dragging SplitPane
Code snippet from
BasicSplitPaneUI.java
protected void startDragging() {
if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
setLastDragLocation(divider.getBounds().x);
dividerSize = divider.getSize().width + 2 * getDividerBorderSize();
if(!isContinuousLayout() && draggingHW) {
nonContinuousLayoutDivider.setBounds
(getLastDragLocation(), 0, dividerSize,
splitPane.getHeight());
}
} else {
setLastDragLocation(divider.getBounds().y);
dividerSize = divider.getSize().height + 2 *
getDividerBorderSize();
gary.collins@East 1999-05-18
Steps to reproduce error:
1: Compile & execute testcase
2: Press Blue "GetMaximumDividerLocation" Button.
3: Take note of the size in the status bar.
4: Drag SplitPane up or Down.
5: Press Blue "GetMaximumDividerLocation" Button again.
6: Look at the number returned in the status line. The difference between
first call and second call is 10 pixels. this is an error.
TestCase:
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
public class GetMaximumDividerLocation extends JFrame implements ActionListener{
public GetMaximumDividerLocation(String title) {
super(title);
start = addButton(buttonPanel,"GetMaximumDividerLocation",Color.blue);
pass = addButton(buttonPanel,"Pass",Color.green);
fail = addButton(buttonPanel,"Fail",Color.red);
//Add Status Bar
statusPanel.setBorder(BorderFactory.createEtchedBorder());
statusPanel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
statusPanel.add(status);
status.setHorizontalAlignment(JLabel.LEFT);
bottomPanel.add(buttonPanel,BorderLayout.NORTH);
bottomPanel.add(statusPanel,BorderLayout.SOUTH);
contentPane.add(bottomPanel,BorderLayout.SOUTH);
contentPane.add(sp,BorderLayout.CENTER);
// Add Window handler
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent event){ System.exit(0);}
});
}
public static void main(String[] args) {
GetMaximumDividerLocation t = new GetMaximumDividerLocation("JSplitPane.getMaximumDividerLocation Test");
t.setSize(600,200);
t.setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
if (evt.getSource() == pass) {
System.out.println("Test Passed");
System.exit(0);
}
else if (evt.getSource() == fail) {
System.out.println("Test Failed");
System.exit(1);
}
else if (evt.getSource() == start) {
// Below calculation is from JDK source code. 2 is for getDividerBorderSize
int test = ((sp.getSize().height - sp.getRightComponent().getMinimumSize().height) - (sp.getDividerSize()+2));
status.setText("Expected="+test+", Returned="+sp.getMaximumDividerLocation()+", are they equal?");
}
}
public JButton addButton(JPanel addComponent, String name, Color color) {
JButton b = new JButton(name);
b.setBackground(color);
b.addActionListener(this);
addComponent.add(b);
return b;
}
private JButton start;
private JButton nextB;
private JButton pass;
private JButton fail;
private JLabel status = new JLabel("Press Blue \"GetMaximumDividerLocation\" Button to start Test.");
private JPanel buttonPanel = new JPanel();
private JPanel bottomPanel = new JPanel(new BorderLayout());
private JPanel statusPanel = new JPanel();
private Container contentPane = getContentPane();
private static JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,new JButton("Button1"),new JButton("Button2"));
}
gary.collins@East 1999-05-19
getMaximumDividerLocation initially returns incorrect value because it is dependant on dividerSize to be correct, initially dividerSize is set to 0.
Side Note: Test was run on a Sparc with OpenWindows. CDE will return a different size based on inset sizes.
Value from Source code
BasicSplitPaneDivider.java
/**
* Size of the divider.
*/
protected int dividerSize = 0; // default - SET TO 0???
From source Code
BasicSplitPaneUI.java
public int getMaximumDividerLocation(JSplitPane jc) {
maxLoc -= (dividerSize + getDividerBorderSize());
dividerSize does not get set correctly until user tries to start
dragging SplitPane
Code snippet from
BasicSplitPaneUI.java
protected void startDragging() {
if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
setLastDragLocation(divider.getBounds().x);
dividerSize = divider.getSize().width + 2 * getDividerBorderSize();
if(!isContinuousLayout() && draggingHW) {
nonContinuousLayoutDivider.setBounds
(getLastDragLocation(), 0, dividerSize,
splitPane.getHeight());
}
} else {
setLastDragLocation(divider.getBounds().y);
dividerSize = divider.getSize().height + 2 *
getDividerBorderSize();
gary.collins@East 1999-05-18
Steps to reproduce error:
1: Compile & execute testcase
2: Press Blue "GetMaximumDividerLocation" Button.
3: Take note of the size in the status bar.
4: Drag SplitPane up or Down.
5: Press Blue "GetMaximumDividerLocation" Button again.
6: Look at the number returned in the status line. The difference between
first call and second call is 10 pixels. this is an error.
TestCase:
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
public class GetMaximumDividerLocation extends JFrame implements ActionListener{
public GetMaximumDividerLocation(String title) {
super(title);
start = addButton(buttonPanel,"GetMaximumDividerLocation",Color.blue);
pass = addButton(buttonPanel,"Pass",Color.green);
fail = addButton(buttonPanel,"Fail",Color.red);
//Add Status Bar
statusPanel.setBorder(BorderFactory.createEtchedBorder());
statusPanel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
statusPanel.add(status);
status.setHorizontalAlignment(JLabel.LEFT);
bottomPanel.add(buttonPanel,BorderLayout.NORTH);
bottomPanel.add(statusPanel,BorderLayout.SOUTH);
contentPane.add(bottomPanel,BorderLayout.SOUTH);
contentPane.add(sp,BorderLayout.CENTER);
// Add Window handler
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent event){ System.exit(0);}
});
}
public static void main(String[] args) {
GetMaximumDividerLocation t = new GetMaximumDividerLocation("JSplitPane.getMaximumDividerLocation Test");
t.setSize(600,200);
t.setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
if (evt.getSource() == pass) {
System.out.println("Test Passed");
System.exit(0);
}
else if (evt.getSource() == fail) {
System.out.println("Test Failed");
System.exit(1);
}
else if (evt.getSource() == start) {
// Below calculation is from JDK source code. 2 is for getDividerBorderSize
int test = ((sp.getSize().height - sp.getRightComponent().getMinimumSize().height) - (sp.getDividerSize()+2));
status.setText("Expected="+test+", Returned="+sp.getMaximumDividerLocation()+", are they equal?");
}
}
public JButton addButton(JPanel addComponent, String name, Color color) {
JButton b = new JButton(name);
b.setBackground(color);
b.addActionListener(this);
addComponent.add(b);
return b;
}
private JButton start;
private JButton nextB;
private JButton pass;
private JButton fail;
private JLabel status = new JLabel("Press Blue \"GetMaximumDividerLocation\" Button to start Test.");
private JPanel buttonPanel = new JPanel();
private JPanel bottomPanel = new JPanel(new BorderLayout());
private JPanel statusPanel = new JPanel();
private Container contentPane = getContentPane();
private static JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,new JButton("Button1"),new JButton("Button2"));
}
gary.collins@East 1999-05-19
- duplicates
-
JDK-4223032 JSplitPane miscalculates maximum divider location before it is moved
-
- Resolved
-