473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Can't clean JLabel

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 1394

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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.