473,467 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can't clean JLabel

1 New Member
I need to clean my labelResult each time on textField Action, but on the first time it adds 'null' in front of string and then - prints new string right after. Please help.

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6.  
  7. public class Frame extends JFrame implements ActionListener {
  8. boolean isDirect = true;
  9. String[] typeStr = {"direct", "invert"};
  10. JLabel labelTip = new JLabel("Choose 'direct' OR 'invert' to print your next line in   direct order or inverted respectively.");
  11. JTextField textField = new JTextField("Some text!", 40);
  12. JComboBox comboBox = new JComboBox(typeStr);
  13. EventProcessing eventProcessing = new EventProcessing();
  14. JLabel labelResult = new JLabel();
  15.  
  16. public Frame() {
  17.     setLayout(new BorderLayout());
  18.     getContentPane().add(labelTip, BorderLayout.PAGE_START);
  19.     getContentPane().add(comboBox, BorderLayout.CENTER);
  20.     getContentPane().add(textField, BorderLayout.AFTER_LINE_ENDS);
  21.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.     textField.addActionListener(this);
  23.  
  24.     pack();
  25. }
  26.  
  27. public void actionPerformed(ActionEvent e) {
  28.     getContentPane().remove(labelResult);
  29.     labelResult = new JLabel();
  30.     labelResult.setText("");
  31.     if (!(comboBox.getSelectedItem()).equals("direct")) {
  32.         isDirect = false;
  33.     } else {
  34.         isDirect = true;
  35.     }
  36.     labelResult.setText(eventProcessing.action(isDirect, textField.getText()));
  37.     getContentPane().add(labelResult, BorderLayout.PAGE_END);
  38.  
  39.     pack();
  40.  
  41. }
  42.  
  43. }
Aug 24 '11 #1
0 1397

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Surya | last post by:
I'm using Microsoft.Project.OLEDB.9.0 provider with a datareader to read data from a .mpp file (Microsoft Project plan) from ASP.NET The problem is All the STRING values, the datareader returns, do...
2
by: Jeffrey Palermo, MCAD.Net | last post by:
I have some classes that control file processing in c#. The files come from a mainframe and may take some time for each to process. I use the Threadpool to process multiple files at once. Each...
1
by: Satish Appasani | last post by:
am developing a web application using Forms Authentication. User is logged out using FormsAuthentication.SignOut(). After logging out, ifthe user clicks Back button in the browser, the user is...
1
by: ad | last post by:
I am useing VS 2005 beta2 to develop my WebApplicaiton. I found that the application variable will be cached when I re-Start_debug my application event I modified some code. Is it a bug or how...
7
by: siggi | last post by:
Hi all, when I do >>>sys.path in IDLE (winXP), i get a horrendously long list of paths, paths I may have used during a lot of trials and errors. How can I clean up sys.path? I mean, trim it of...
5
by: JMonee | last post by:
Hi everyone .. I whoud like to ask you about some points.. when I use say for loop .. and i read from the user string using nextLine(); at the first time it is work .. put in the 2nd it does not...
1
by: bruce628 | last post by:
I want to use SWT tab compnent and make it be multiline,but I fail.please see the class TabFolderExample. Can aneone help me? import java.awt.BorderLayout; import...
0
Lokean
by: Lokean | last post by:
Hi all, I have a proc that runs once per minute that monitors the health a function of an application. When the check fails, I throw four queries at the application database to report on what the...
10
by: Simon | last post by:
As title. How to clean out VSWebCache? Any good way to do that? Thanks.
1
by: rajarameshchint | last post by:
import java.util.*; import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.print.*; public class sd7 extends JFrame implements...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.