public void layoutContainer(Container parent) {
int width = parent.getWidth();
int height = parent.getHeight();
Insets insets = parent.getInsets();
Dimension nextD = preferredSize(nextButton);
Dimension previousD = preferredSize(previousButton);
int buttonsWidth = Math.max(nextD.width, previousD.width);
int editorHeight = height - (insets.top + insets.bottom);
// The arrowButtonInsets value is used instead of the JSpinner's
// insets if not null. Defining this to be (0, 0, 0, 0) causes the
// buttons to be aligned with the outer edge of the spinner's
// border, and leaving it as "null" places the buttons completely
// inside the spinner's border.
Insets buttonInsets = UIManager.getInsets("Spinner.arrowButtonInsets");
if (buttonInsets == null) {
buttonInsets = insets;
}
/* Deal with the spinner's componentOrientation property.
*/
int editorX, editorWidth, buttonsX;
if (parent.getComponentOrientation().isLeftToRight()) {
editorX = insets.left;
editorWidth = width - insets.left - buttonsWidth - buttonInsets.right;
buttonsX = width - buttonsWidth - buttonInsets.right;
} else {
buttonsX = buttonInsets.left;
editorX = buttonsX + buttonsWidth;
editorWidth = width - buttonInsets.left - buttonsWidth - insets.right;
}
int nextY = buttonInsets.top;
int nextHeight = (height / 2) + (height % 2) - nextY;
int previousY = buttonInsets.top + nextHeight;
int previousHeight = height - previousY - buttonInsets.bottom;
setBounds(editor, editorX, insets.top, editorWidth, editorHeight);
setBounds(nextButton, buttonsX, nextY, buttonsWidth, nextHeight);
setBounds(previousButton, buttonsX, previousY, buttonsWidth, previousHeight);
}
|