简体   繁体   中英

is there a way to access the property of component inside another container?

I am working on a project(shown below).

When I type a value in textField the slider will correspond the same value, meanwhile the color will change, as well as the label(R: 0,G:0,B:0) .

Also when you slide slider, the text of textfield, color, and label will change (I have already achieve this function). By the way, three sliders are put in a panel.
I tried to get component of panel, but there is no getValue() method which is weird.

Is there a way to solve this? Any help will be appreciated. (I am totally new to programming)

在此处输入图片说明

The easiest way to accomplish what I think you are trying to do is to use Beans Binding , at least if you use NetBeans as your IDE. Bind the JTextField for the Red color to the JSlider for the Red color. Do the same for Green and Blue components. At its most basic level, beans binding is a way to connect bean properties without using event listening and handling code.

在此处输入图片说明

It's really not exactly clear what you are trying to accomplish here since you have not responded to the comment I provided related to your Post so I'll just leave you with a gif Image displaying a demo of what Beans Binding can look like in action. The demo code is too large to post here but if the provided above link is not enough to assist you then (anyone) please feel free to e-mail me for the demo source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM