开发者

Increase the size of the arrows on the JSpinner

How to increase the 开发者_开发百科size of the arrows on the JSpinner.


For vertical increase: Just increase JSpinner's height. For horizontal increase: Use a special layout manager that takes the width of arrows and sets the bounds according to it. JSpinner has three components inside: The first two are up and down arrows, the third one is the text field.


I created this method that handles changing the button size. I wanted a large button for touchscreen. I use this for setting the time, both hours and minutes. It handles 2 characters wide perfectly.

    public static void setScrollBarWidthOnJSpinnerWith2Numbers(JSpinner spinner) {
    spinner.setLayout(null);
    int fontSize = 160;
    int buttonSize = 87;
    Component c = spinner.getComponent(0);
    if (c instanceof BasicArrowButton) {
        BasicArrowButton b = (BasicArrowButton) c;
        b.setBounds(190, 2, 0, 0);
        b.setSize(buttonSize, buttonSize);
    }
    Component c2 = spinner.getComponent(1);
    if (c2 instanceof BasicArrowButton) {
        BasicArrowButton b = (BasicArrowButton) c2;
        b.setBounds(190, buttonSize + 2, 0, 0);
        b.setSize(buttonSize, buttonSize);
    }
    Component c3 = spinner.getComponent(2);
    if (c3 instanceof NumberEditor || c3 instanceof ListEditor) {
        DefaultEditor ne = (DefaultEditor) c3;
        ne.setBounds(2, 2, 10, 20);
        ne.setSize(180, fontSize);
        ne.setAlignmentY(0);
    }
    spinner.setFont(new Font("Tahoma", Font.PLAIN, fontSize));
    spinner.setSize(new Dimension(279, 179));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜