Accessing JButtons in tabbed pane

前端 未结 1 1020
旧时难觅i
旧时难觅i 2021-01-29 09:44

I am creating a tabbed pane for the amount of rooms that I have and I am creating a light button for each light that each room has and adding it to the tabbed pane.

How

相关标签:
1条回答
  • 2021-01-29 10:00

    Why on earth would you try to access the button and fire the event. The UI is only a view on the data. Why not manipulating the data directly ? If you figure out a way to find that button and trigger a click on it (which is not that hard), you are screwed when you decide to change your layout afterwards.

    So just share your data behind your UI between master and client, and make sure your UI is updated when something is changed on the data (and vice versa, the UI should update the data when the user makes changes in the UI). That way you can share the state.

    Try a quick search on Google for MVC (model-view-controller) if you want some more reading on this.

    But if still want to do a click, each button has a doClick method which does the same thing as if the user had pressed and released the button (quote from the javadoc).

    0 讨论(0)
提交回复
热议问题