在另一个类更改数据后更新JTable

时间:2018-05-27 19:14:41

标签: java swing jtable mouselistener

我正在努力更新表的内容。

实际上,代码的作用是:它用一些JTextField打开一个JDialog(没有内部类)。

提交新数据后,它可以直接用于保存tab2 JTable的类。当我再次为同一个表行打开JDialog时,该表将正确更新,但我希望它在EditData提交数据后立即更新。

我明白为什么现在没有,但现在我被卡住了。

我如何知道EditData是否已关闭,甚至更好,是否按下了提交按钮,或者 - 甚至更好 - 如果我在EditData中定义一些布尔成功(),它会告诉我输入是否正确;如何从主类访问它?

.drag-file-ct .x-innerhtml {
  pointer-events: none;
}

.drag-file-fadeout {
  opacity: 0;
  -webkit-transition: all 1s ease-in-out;
  transition: all 1s ease-in-out;
}

.drag-file-label {
  font-size: 18px;
  padding-top: 30px;
  text-align: center;
  pointer-events: none;
}

.drag-file-icon {
  font-family: FontAwesome;
  display: block;
  font-size: 64px;
  margin-top: 50px;
  text-align: center;
  pointer-events: none;
}
.active .drag-file-icon {
  display: block;
}
.active .drag-file-icon:after {
  content: "\f058";
  color: #8BC34A;
}
.dropped .drag-file-icon {
  display: block;
}
.dropped .drag-file-icon:after {
  content: "\f013";
  color: #9E9E9E;
}
.nosupport .drag-file-icon {
  display: block;
}
.nosupport .drag-file-icon:after {
  content: "\f119";
  color: #9E9E9E;
}

1 个答案:

答案 0 :(得分:0)

  

如何判断EditData是否已关闭,

  • 将其设为模态对话框,模态为当前调用父窗口。这样,当前代码流将停止在此对话框可见的位置,并且不会再继续,直到对话框不再可见 - 行下面的行 。< / LI>
  • 所以不要让EditData使本身可见,即在其构造函数中没有public class Brain : MonoBehaviour { public GameObject Output, Input, AdjustDbInput; string ProcessInput; public void Process (Text TextInput) { ProcessInput = TextInput.text; if (System.IO.File.Exists(Application.dataPath + "/" + ProcessInput + ".txt")) Output.GetComponent<Text>().text = System.IO.File.ReadAllText($"{Application.dataPath}/{ProcessInput}.txt"); else { Input.gameObject.SetActive(false); AdjustDbInput.gameObject.SetActive(true); } } public void Adjust (Text Response) { StreamWriter writer = new StreamWriter(${Application.dataPath}/{ProcessInput}.txt"); writer.WriteLine(Response.text); writer.Close(); Input.gameObject.SetActive (true); AdjustDbInput.gameObject.SetActive (false); } } 。而是让调用代码在需要的地方和时间创建实例,然后在需要的地方和时间将其设置为可见。
  

甚至更好,是否按下了提交按钮,或者 - 甚至更好 - 如果我在EditData中定义一些布尔成功(),它会告诉我输入是否正确;

  • 创建模态对话框的一种方法是使用JOptionPane,如果使用setVisible(true),此对话框将返回一个int,告诉您按下了哪个按钮。
  • 为了实现这一点,EditData需要是一个JPanel,你可以放在JOptionPane中(如果你愿意的话,也可以在你自己的JDialog中,如果你愿意的话)。
  • 或者,如果你喜欢自己滚动JDialog,再次将其设为模态。给JButtons提交或取消。在使对话框可见时,将对话框对象的布尔字段设置为false,然后在提交按下时,将该字段更改为true。在按下任何按钮时,使对话框不再可见。这样,一旦调用代码不再可见,调用代码就可以查询对话框的状态。
  

如何从主类访问它?

使EditData成为类中的一个字段,这样您就可以在正确处理后查询其状态。