我对 Java 编码相当陌生,我正在尝试从 double 中获取一个数字以显示到 JSwing 文本框中。
我遇到问题的代码:
txtCounter = new JTextField();
txtCounter.setText(counter); //Error here Jtextcomponent not available for Double
txtCounter.setEditable(false);
txtCounter.setToolTipText("Shows time that has passed.");
txtCounter.setBounds(10, 69, 100, 20);
frmTimer.getContentPane().add(txtCounter);
txtCounter.setColumns(10);
我可以在这种情况下使用他们的不同陈述吗?
最佳答案
您需要将 counter
的字符串表示形式传递给 setText()
。以下任一行都可以工作:
txtCounter.setText(String.valueOf(counter));
或者:
txtCounter.setText(counter + "");
关于java - 使用 Windowbuilder 和 Java 显示双重使用文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21070500/