根据条件更改 JSlider 的最小值和最大值 [英] Changing the min and max value of JSlider depanding on condition
问题描述
我正在 Netbeans 中创建一个 Swing GUI.这个 GUI 的目的是打开一个(缓冲的)图像(在 JLabel 中作为图标)并对其应用仿射变换.现在有 4 个转换我正在做如下.
I'm creating a Swing GUI in Netbeans. The purpose of this GUI is to open an (buffered)image (in a JLabel as icon) and apply Affine transforms on it. Now there are 4 transforms that I'm doing as follows.
现在,每个变换都需要两个滑块来更改 X 和 Y 值,但旋转除外,它只需要一个.我这样做是因为它比必须为所有 4 种类型的转换做四个选项卡要好得多.此外,我希望它是这样的,例如,如果旋转图像,则可以通过从下拉列表中选择剪切来剪切相同旋转的图像.
Now, each transform requires two sliders to change the X and Y value, except that of rotate, which will require only one. I did it this way since its much better than having to do four tabs for all 4 types of transforms. Also I want it to be such that , for example, if an image is rotated, the same rotated image can be sheared by selecting shear from the Drop down list.
问题是(是):如何重新绘制标签图标并在同一个重新绘制的图像上应用不同的变换?另外,如何根据所选效果更改 JSlider 的最小值和最大值?
The problem is (are): How do i repaint the label icon and apply different transform on the same repainted image? Also, how do i change the minimum and maximum value of JSlider depanding on the effect selected?
推荐答案
你应该存储最初加载的 BufferedImage,并创建它的副本 - 这样你就不会破坏"它.
You should store originally loaded BufferedImage, and create its copy - that way you won't "destroy" it.
至于更改值,有 setMaximum 和 setMinimum 方法 - 将侦听器添加到列表,如 Oracle 教程 并修改值.
As for the changing value there are methods setMaximum and setMinimum - add listener to list, as stated in Oracle tutorial and modify the values.
这篇关于根据条件更改 JSlider 的最小值和最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!