Java SWT Refresh Multiple Shells From Button

Deadly 提交于 2019-12-06 13:44:58

问题


I am building an app that accesses a database and currently I have a SWT Shell that displays the main table. From this table users can open individual records and from inside the records form the user can open a second form that is of the same type but contains different data. If the record in either form is updated the update is reflected in the main form. My problem is I can't update the first record form that is opened. Is there a way to force an update or redraw for all open forms of a certain type or is there a way I can update multiple shell of the same type at the same time. The screen shot below shows what I am trying to do.

Screenshot details

  • A
    • Main Form
    • This form currently gets updated when either of the 2 secondary forms change data in the database. This is done by reloading the table from the secondary forms
  • B
    • This is the first instance of the data form
  • C
    • This is the second instance of the data form.
    • It is opened from first data form by clicking the open button. What I am trying to do is have the first data form refresh when I change something in the second form.
    • For example I opened the record for the tag 295 White and when I update the data for this record I want the changes to be shown in the record form for 26 White

I know this is a hard to understand question, so feel free to ask for more details I am pulling my hair out trying to figure this out.


回答1:


In the main form, you set up a Java Stack.

Stack<DataForm> stack = new Stack<DataForm>(); 

You pass a reference of this Stack to the data form(s).

In the constructor of the data form, you pass the data form instance.

stack.push(this);

In the destructor of the data form (on exit), you remove the data form instance.

int pos = stack.search(this);
stack.remove(pos);

When you want to refresh all of the forms, you loop through the stack.

for (DataForm dataForm : stack) {
     // do the refresh
}


来源:https://stackoverflow.com/questions/11564503/java-swt-refresh-multiple-shells-from-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!