首页 \ 问答 \ 麻烦添加文本到JTextArea(append或settext)(Trouble Adding text to JTextArea (append or settext))

麻烦添加文本到JTextArea(append或settext)(Trouble Adding text to JTextArea (append or settext))

所以我正在制作的程序使用2个线程:一个用于GUI,一个用于完成工作。

我希望工作线程/类的更新在GUI类中的JTextArea上打印出来。 我尝试的一切似乎都没有用。 我在行后面添加了一些行来打印文本,以便在JTextArea中添加文本以确保它已经到达行,但每次控制台都有文本但GUI中的JTextArea没有发生任何变化。

public static void consoleText(String consoleUpdate){
    GUI.console.append(consoleUpdate);
}

我在工人阶级试过这个,但什么也没发生。 有谁知道如何解决我的问题?

编辑:

MAIN.JAVA

public class main {
public static void main(String[] args) {
    Thread t1 = new Thread(new GUI());
    t1.start();
}

GUI.JAVA

public class GUI extends JFrame implements Runnable{

public static JTextArea console;
private final static String newline = "\n";

public void run(){
    GUI go = new GUI();
    go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    go.setSize(350, 340);
    go.setVisible(true);
}

public GUI(){
setLayout(new FlowLayout());
console = new JTextArea(ConsoleContents, 15, 30);
add(console);
}

WORK.JAVA

...{
consoleText("\nI want this text on the JText Area");
}

public static void consoleText(String consoleUpdate){
    GUI.console.append(consoleUpdate);
}

So the program I am making uses 2 threads: One for the GUI and one to do the work.

I want updates from the work thread/class to print out on JTextArea in GUI class. Everything I tried didn't seem to work. I added lines to print out text on the console right after lines to add text to the JTextArea to make sure it had got to the line but everytime console got text but no changes happened to JTextArea in the GUI.

public static void consoleText(String consoleUpdate){
    GUI.console.append(consoleUpdate);
}

I tried this in the work class but nothing happened. Anyone know how to fix my problem?

Edit:

MAIN.JAVA

public class main {
public static void main(String[] args) {
    Thread t1 = new Thread(new GUI());
    t1.start();
}

GUI.JAVA

public class GUI extends JFrame implements Runnable{

public static JTextArea console;
private final static String newline = "\n";

public void run(){
    GUI go = new GUI();
    go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    go.setSize(350, 340);
    go.setVisible(true);
}

public GUI(){
setLayout(new FlowLayout());
console = new JTextArea(ConsoleContents, 15, 30);
add(console);
}

WORK.JAVA

...{
consoleText("\nI want this text on the JText Area");
}

public static void consoleText(String consoleUpdate){
    GUI.console.append(consoleUpdate);
}

原文:https://stackoverflow.com/questions/13053107
更新时间:2022-06-27 17:06

最满意答案

我想你正在寻找一些旧的文档,autodesk决定保留这种方法,请查看http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_class_m_node_message_html


I think you are looking to some old documentation and autodesk decided to keep that method please check this http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_class_m_node_message_html

相关问答

更多
  • 国内MAYA比较权威的培训机构北边有火星时代,水晶石,南边有:CGWANG和环球数码。在选择的时候最好看看那个培训机构的学生作品,当然老师的作品也是很重要的衡量标准,推荐cgwang ,性价比最好的。重要的是实力也是最牛的。
  • MAYA的知识,实在太多了,MAYA主要分几大部分,如果你想学的话,可以在网上下栽一些教程,在到学校去进修下。
  • 1. 首先在 C:\ 下创建一个名为 FLEXLM 的资料夹; 2. 拷贝 aw.dat 和 awkeygen.exe 到 FLEXLM 的资料夹下; 3. 安装 MAYA (最好在默认路径); 4. 点选开始-->所有程式-->Autodesk-->common utilities-->FlexLM license utilities; 5. 转到“system settings”选项卡,拷贝“Ethernet address”项后面的字串; 6. 使用记事本开启 FLEXLM 资料夹 ...
  • cylinder_01是变换,用于处理平移,旋转,缩放等。 polyCylinder1是形状,它包含顶点,多边形,着色器连接等。 形状是变换的代表。 如果选择“ 显示”>“形状”,则可以在“大纲视图”中看到它 cylinder_01 is the transform, which handles translation, rotation, scale, etc. polyCylinder1 is the shape, which holds the vertices, polygons, shader c ...
  • 我想你正在寻找一些旧的文档,autodesk决定保留这种方法,请查看http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_class_m_node_message_html I think you are looking to some old documentation and autodesk decided to keep that method please check this http://help.autodesk.com/ ...
  • 您可以在MAnimMessage 文档中继。这个回调可以帮助您找到关键帧操作并插入回调,例如: OpenMayaAnim.MAnimMessage.addAnimKeyframeEditedCallback( obj.addKeyframeDelta, None) You can relay on MAnimMessage Docs .This callback can help you to find the keyframe action and plug a callback eg : OpenMa ...
  • 听起来你需要选择回调。 有了OpenMaya的api,就有了MEventMessage ,还有带有cmds scriptJob 。 这两个例子都可以在这里找到: 如何从Maya中获取突出显示场景中物体的事件? 出于性能原因,我建议使用MEventMessage而不是scriptJob 。 Sounds like you need a selection callback. With OpenMaya's api there's MEventMessage, and also scriptJob with c ...
  • 伙计们, 终于找到了。 它完全不是它应该的位置。 Autodesk有一些奇怪的做事方式。 这里是: void removeMyNode(MObject &node, void *clientData) { MFnDependencyNode nodeFn(node); MGlobal::displayInfo(MString("Removal callback node: ") + nodeFn.name()); } MDGMessage::addNodeRemovedCallback(remov ...
  • 权威名称是listAttr名称; 您在UI中看到的名称不可靠,因为AETemplate可以以任何方式覆盖它们。 AE经常呈现用于计算实际值的虚假属性 - 例如,摄像机在属性编辑器中具有angleOfView ,但设置它实际上会更改focalLength属性; 摄像机节点上没有angleOfView 。 因此,您可能需要做一些侦探工作来弄清楚可见UI的确在做什么。 玩滑块和观看历史是通常的第一步。 FWIW dict(zip(cmds.listAttr(), cmds.listAttr(sn=True))) ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)