public class ParserGUI extends javax.swing.JFrame {
public ParserGUI() {
initComponents();
}
private void initComponents() {
comText = new JTextArea();
internToggle = new javax.swing.JToggleButton();
comText = new javax.swing.JTextArea();
ComText.setColumns(20);
ComText.setEditable(false);
ComText.setRows(5);
ComText.setLineWrap(true);
ComText.setWrapStyleWord(true);
ComText.setText(uids.toString()); // uids includes the UID's
internToggle.setText("Nur interne");
internToggle.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
InternToggleActionPerformed(evt);
}
});
private void internToggleActionPerformed(ActionEvent evt) {
System.out.println("Intern");
if (externToggle.isSelected()) {
externToggle.setSelected(false);
}
if (internToggle.isSelected()) {
String[] person = comText.getText().split("; ");
StringBuffer newPerson = new StringBuffer();
for (String string : person) {
if (string.matches("((?i)u)([0-9]{6})")) {
newPerson.append(string + "; ");
}
}
comText.setText(newPerson.toString());
}
}
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
// <editor-fold defaultstate="collapsed"
// desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase
* /tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ParserGUI.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
}
// </editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ParserGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextArea comText;
private javax.swing.JToggleButton internToggle;
// End of variables declaration我想通过单击JToggleButton (internToggle)来更新我的JTextArea (comText)。但当我点击按钮时,什么也没有改变。
我在SO和google中搜索,但所有的解决方案在我的程序中都不起作用。
程序员应该做的事情:
我的TextArea包含许多不同的用户ID的uids.toString()。
示例-内容:u100125; u100149; u100187; u100364; u110207; u110318; u111949; u112850; u114345; u117205; u118421; u119058; u123362; u128621; u143754; u147190; u149220; u149788; u149911; u160017; u160081; u161927; u162659; u163383; u165021; u165363; u165534; u165765; u166052; u166731; u166912; u200965; u201334; u201942; u202144; u202291; u202293; u202544; u202670; u202899; u202920; u202928; u202975; u203103; u203271; u203499; u203739; u203960; u204011; u204030; u204333; u204652; u205166; u205203; u205420; u205595; u206596; u206741; u207063; u207455; u207467; u207627; u207742; u207788; u207797; u208344; u208419; u208637; u208820; u209382; u209903; u210041; u210690; u210767; u210854; u210875; u212119; u213175; u213517; u213940; ue01545; ue03732; ue05728; ue06895; ue53655; ue54224; ue55155; ue55385; ue57760; ue58142;
现在我想用切换按钮从ue-ID中过滤掉u-ID。
我的方法internToggleActionPerformed起作用了。newPerson()包含所有u-ID,但TextArea什么也不做。如何更新TextArea
发布于 2012-09-18 21:21:54
就这样办。
这是我的日食的一个错误。在我的公司,我们有一个Eclipse和我们自己的插件。新版本使用GIT,但我自己的小项目是用SVN开发的,它的插件有问题。所以我所有的GUI应用程序都启动了,但后来被冻结了。
无论如何,谢谢你的大力帮助!
发布于 2012-09-14 18:29:36
我已经将您的代码片段封装到一个可运行的应用程序中,请参阅http://pastebin.com/S2A3drXk。它可以像预期的那样工作,不需要调用各种/repaint()/pack()。我建议以此为起点,一步一步地修改它,直到您添加完所有附加代码。
免责声明:我非常了解Java命名约定。我的目的是使用与OP相同的侦听器,而让OP去熟悉Java命名和编码约定并适当地应用它们。
发布于 2012-09-14 18:17:43
使用此tutorial。
https://stackoverflow.com/questions/12421193
复制相似问题