开发者

Scrollbar event handling, how to keep number grabbed static

As the title suggests I have a program with a scrollbar interface. The problem is that the program uses the same three scrollbars for four sets of different numbers, once the change has been made to another set of numbers the scrollbar remains on the same values from the previous set of numbers

        float RedAmount1 = lightDimmer1.getValue();
        float GreenAmount1 = lightDimmer2.getValue();
        float BlueAmount1 = lightDimmer3.getValue();

        diffuseSwitch[0] = RedAmount1;          
        diffuseSwitch[1] = GreenAmount1;
        diffuseSwitch[2] = BlueAmount1;

        float StoreColours1[] = {RedAmount1,GreenAmount1,BlueAmount1};

        开发者_开发百科int StoreColourRed = (int)StoreColours1[0];
        int StoreColourGreen = (int)StoreColours1[1];
        int StoreColourBlue = (int)StoreColours1[2];

        if(diffuseSwitch[0] != StoreColourRed)
        {
         lightDimmer1.setValue(StoreColourRed);
        }

This piece of code is placed within a scrollbars event handling section so the number am trying to compare float StoreColourRed and diffuseSwitch[0] keep being changed to the values of the latest set of numbers instead of keeping the previous set of values.

any help would be much appreciated


Use a very simple class to hold your values, for example:

private static class MyColor {
    float red, green, blue;
}

You should be able to use getValueIsAdjusting() and setValueIsAdjusting() to determine when the values are stable. You may also want to us JRadioButton or JComboBox to select which set of values is being manipulated.

Addendum: I carelessly assumed JSlider when reading the question. Also, adjusting is probably irrelevant. JTabbedPane is another choice for selecting which set of values is being manipulated.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜