settext

Memory leak when using setText

风格不统一 提交于 2019-12-23 13:15:07
问题 I have noticed that I have a memory leak in my program. I have traced the problem to the line. Clock.setText("" + h + ":" + df.format(m) + ":" + df.format(s)); I have googled this and it seems to be a common problem but I have not found an answer. Does anyone know a fix? Here is the entire code: package CodeBits; import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt

Mechanisms of setText() in JTextArea?

蹲街弑〆低调 提交于 2019-12-20 03:42:19
问题 I try to show some text in my JTextArea in runtime. But when I use a loop of setText to show text in order, it only show the text of the last loop Here is my code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { for (int i=0;i<10;i++) jTextArea1.setText("Example "+i); } I want it to show "Example 1", "Example 2",..,"Example 9" . But it only show one time " Example 9 " Anyone can explain it for me?? 回答1: setText does just that, it "sets the text" of field to the value

textView setText() NullPointerException

戏子无情 提交于 2019-12-20 03:14:50
问题 I have an almost completely Vanilla App. All I'm trying to do is change the text of a textView, but it gives me a NullPointerException. I have no XML configuration, no added methods, nothing special. I checked my class, and it's pointing to the correct XML, and the XML does have a textView element in it with the correct id. I have also tried creating the textView instance outside of onCreate() on the class level, and the app just fails to start no matter what. I'm sure I'm overlooking simple,

Cannot set button text to “<<<”

蹲街弑〆低调 提交于 2019-12-19 23:24:54
问题 I'm trying to set the text of a button to "<<<" from my xml but I get an "Error:(20) Error parsing XML: not well-formed (invalid token)" <Button android:id="@+id/test" android:text="<<<" android:layout_width="wrap_content" android:layout_height="match_parent" /> So I jumped over to my strings.xml to enter it in there and that clearly won't work. <string name="abc"> <<< </string> Is there a workaround for this? 回答1: These are html entities, works in android studio as well: > can be replaced

EDT is not working properly with recursive method while updating lable

家住魔仙堡 提交于 2019-12-18 09:51:30
问题 //search files and directories public void getFile1(String directoryName) throws Exception { File directory = new File(directoryName); String str = directory.getName(); File[] fList = directory.listFiles(); if (fList != null) { for (File file : fList) { { if (file.isFile()) { st = (file.toString()); System.out.println(st); jLable1.setText(st);//jLable1 is not updating. String fileName = file.getName(); String strvirusCount=Integer.toString(virusCount); } else if (file.isDirectory()) {

Difference between setText() and append()

有些话、适合烂在心里 提交于 2019-12-17 16:35:07
问题 I'm curious about the difference setText() and append() are creating. I'm writing a very basic editor with line numbers. I have a TextView to hold line numbers on the left, paired with an EditText on the right to hold the data. Here's the XML: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top"> <TextView android:id="@+id/line

How to call setText() using a Float? [duplicate]

巧了我就是萌 提交于 2019-12-14 03:36:40
问题 This question already has an answer here : How to call setText() using a Float data type? (1 answer) Closed 5 years ago . i tried to call the setText() using the float but it dosnt seem to work can somone help me fix the problem? public class Bmi extends MainActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bmi); final EditText h = (EditText)findViewById(R.id.editText2); final EditText w = (EditText

JButton settext specific position

為{幸葍}努か 提交于 2019-12-14 02:28:25
问题 I have a JButton with an image icon and I need to position the text. Is there a way to position the text of a JButton in a specific position instead of using CENTER,LEADING, TOP and so on? 回答1: I've never tried it on a JButton before, but maybe you can add a JLabel as a component on the button. Then you can use layout managers or Borders to position the label more appropriately. Here are some example of adding a component to a JLabel with an Icon: import java.awt.*; import javax.swing.*;

setText is not working inside a while loop

和自甴很熟 提交于 2019-12-13 09:26:22
问题 why is that? while (flag) { outCPU.setText(getCpuInfo()); } getCpuInfo returns string, if I try to write this method's return out into a log, there is everything that should be, but nothing happens to textview.. 回答1: It will not work... display will update after your function finishes. Try this boolean flag; private void updateTextView(){ outCPU.setText(getCpuInfo()); if(flag){ outCPU.post(new Runnable(){ public void run(){ updateTextView(); } }); } } private void your_function(){ if(flag){

why does my app crash when I use the setText Mehod? [duplicate]

送分小仙女□ 提交于 2019-12-13 08:49:09
问题 This question already has answers here : android.content.res.Resources$NotFoundException: String resource ID #0x0 (6 answers) Closed 2 years ago . QUESTION: Why is my app crashing whenever I try to use the setText() method to assign random Numbers as my Buttons' text? My Goal is to set random numbers to the buttons and if the user clicks the button with the larger number, he/she is awarded a point. I debugged the program and found the logic to be working correctly. However the app keeps