简体   繁体   English

有没有办法访问另一个容器内组件的属性?

[英]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) .当我在textField输入一个值时,滑块将对应相同的值,同时颜色会发生变化,以及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).另外滑动滑块时,textfield的文字、颜色、标签都会发生变化(这个功能我已经实现了)。 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.我试图获取面板的组件,但没有奇怪的getValue()方法。

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.完成我认为您正在尝试做的事情的最简单方法是使用Beans Binding ,至少如果您使用 NetBeans 作为您的 IDE。 Bind the JTextField for the Red color to the JSlider for the Red color.绑定JTextField中红色JSlider的红色 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.在最基本的层面上,bean 绑定是一种无需使用事件侦听和处理代码即可连接 bean 属性的方法。

在此处输入图片说明

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.由于您还没有回复我提供的与您的帖子相关的评论,因此实际上并不完全清楚您要在这里完成什么,因此我将给您留下一个 gif 图像,其中显示了Beans Binding在操作中的样子的演示。 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.演示代码太大,无法在此处发布,但如果上面提供的链接不足以为您提供帮助,那么(任何人)请随时给我发送电子邮件以获取演示源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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