JtextField.setText()

im having problem with JTextField.setText()... let say i have a vector containing multiple strings and i wanna set the text of a jtextfield with one of my vector's element i do:
JTextField.setText((String)Vector.firstElement());
but how come in my jtextfield the new string isnt showing... do i need to repaint my whole frame????
thx

You don't supply enough info to know the problem. You shouldn't have to repaint. Where is your JTextField Defined. If you defined inside a constructor or method, you can get the results you are having.

Similar Messages

  • JTextField.setText() please help...

    i have a field in my table that is in date format.
    txtempdate.setText(rsmastempl.getDate("empdate"));
    this produce an error.
    how will i display my date filed in my table in a TextBox?
    thank you for helping.
    killuasoft

    Christ boy! Did that hurt?
    Try txtempdate.setText(String.valueOf(whatever));
    I'm pretty drunk now, so I'm gonna hit the party.
    L8r

  • JTextField Dilemma??

    I am a beginner Java program. I have made a screen using swing. It has three panels on a frame and laid out using different layouts.
    Now a button is clicked on one panel and I want it to clear all the JTextFields in another panel.
    I have an ActionListener for the button and am using JTextField.setText("") .
    It throws an exception:
    "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"
    Why would this happen?
    Also the same thing happens when I try a button to get the data from these JTextFields using JtextField.getText();
    Do I have to implement ActionListener or DocumentListener for JTextFields also?
    Thanks.

    Maybe I should give some of my code to make my problem clear.
    public class InputFrame extends JFrame {
         public InputFrame(){
              setTitle("Input Screen");
              setSize(500,400);
              JPanel p1=new JPanel();
              p1.setLayout(new BoxLayout(p1,BoxLayout.Y_AXIS));
              JPanel plr=new JPanel();
              plr.setBorder(new EtchedBorder());
              plr.setLayout(new GridLayout(5,2,5,5));
              plr.add(new JLabel());
              plr.add(new JLabel("Date (yyyy-mm-dd)"));
              JTextField dtField=new JTextField("",1);
              plr.add(dtField);
              plr.add(new JLabel());
              plr.add(new JLabel());
              plr.add(new JLabel("Category"));
              JTextField catField=new JTextField("",1);
              plr.add(catField);
              plr.add(new JLabel());
              p1.add(plr);
              getContentPane().add(p1,BorderLayout.CENTER);
              JPanel p2=new JPanel();
              p2.setLayout(new BoxLayout(p2,BoxLayout.Y_AXIS));
              p2.setBorder(new EtchedBorder());
              p2.add(new JLabel("Choose the check-boxes and then enter the required data."));
              p2.add(new JLabel("If the check-boxes are not clicked, then that data will not be considered."));
              getContentPane().add(p2,BorderLayout.NORTH);
              JPanel p3=new JPanel();
              p3.setLayout(new BoxLayout(p3,BoxLayout.X_AXIS));
              p3.setBorder(new EtchedBorder());
              p3.add(new JLabel(" "));
              JButton MainButton=new JButton("Main Menu");
              p3.add(MainButton);
              JButton ClearButton=new JButton("Clear Data");
              p3.add(ClearButton);
              MainButton.addActionListener(m);
              ClearButton.addActionListener(c);
              getContentPane().add(p3,BorderLayout.SOUTH);
         }//end constructor
         //listener for main button
         ActionListener m=new ActionListener(){
              public void actionPerformed(ActionEvent e){
                   //open main screen
                   MainFrame mframe=new MainFrame();
                   mframe.setVisible(true);
                   dispose();
    //TODO:listener for clear button-THIS IS WHERE THE ERROR OCCURS!
         ActionListener c=new ActionListener(){
              public void actionPerformed(ActionEvent evt){
                   //clear all the fields
                   dtField.setText(" ");
                   catField.setText(" ");
                   accnoField.setText(" ");
                   accnameField.setText(" ");
                   amtField.setText(" ");
                   dispose();
         private JButton MainButton;
         private JButton ClearButton;
         private JButton SaveButton;
         private JButton ExitButton;
         private JTextField dtField;
         private JTextField catField;
         private JTextField accnoField;
         private JTextField accnameField;
         private JTextField amtField;
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              JFrame frame1 = new InputFrame();
              frame1.setVisible(true);
              frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    So I am trying to click a button and clear out the text fields. But its giving me errors. Any ideas why?
    Thanks.

  • JTextField does not visualize the text!

    Hello everybody,
    i have a problem with JtextFields.
    I have a Jtable with a ColumnHeader that contains a Button, a combobox and a JTextField.
    Normally i have 3 columns. When i try to move from a textfield to another textfield i can write in this one but the text is not visualized and i do not se the cursor in it.
    If i click a second time in the textfield, then the text gets visible.
    Here after the code of my UIText which extends JTextField.
    package com.wuerth.phoenix.ui;
    import com.wuerth.phoenix.ui.lov.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import com.wuerth.phoenix.ui.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.util.Locale;
    import java.text.*;
    import com.wuerth.phoenix.util.PString;
    * This object is a generic ui field. Use them to get alphanumeric
    * text.
    * @author ing. Davide Montesin '99<BR><i>[email protected]</i>
    public class UIText extends JTextField implements TextEditor, PhoenixUIElement, FocusListener, KeyListener, ActionListener
    private DefaultPhoenixUIElement dui;
    // This object (is) was used by updateCorrect to find the correct background color
    // It is used for UIComboBox too.
    // protected final JTextField _jtextfield = new JTextField();
    // Background Color (mtm 010327 - UI Bug)
    private Dimension _preferredSize = null;
    private boolean _onlyUpperCase = false;
    String _oldText;
    * Construct a new UIText with the default length(15).
    public UIText()
    this(15);
    * Construct a new UIText with the specified length.
    public UIText(int length)
    super(length);
    setOnlyUpperCase(UIConfiguration.get().isUITextOnlyUpperCase());
    this._oldText = "";
    this.dui = new DefaultPhoenixUIElement(this);
    this.addFocusListener(this);
    this.addKeyListener(this);
    this.addActionListener(this);
    * Set to true if the object should return only uppercase String. This method
    * have priority over the UIConfiguration.
    * @param c if true the getAsText method will return a uppercase string.
    * @see com.wuerth.phoenix.UIConfiguration#setUITextOnlyUpperCase
    public void setOnlyUpperCase(boolean c)
    _onlyUpperCase = c;
    * Tell the object that this field is required. The field use warning color and error color
    * to tell to the user this requireness.
    public void setRequired(boolean r)
    this.dui.setRequired(r);
    this.updateCorrect();
    * @see setRequired
    public boolean getRequired()
    return this.dui.getRequired();
    * Set the mode for the element. Valid modes are: PhoenixUIElement.INSERT,
    * PhoenixUIElement.LOOKUP AND PhoenixUIElement.FIND. The mode influence the
    * validation process.
    public void setMode(int m)
    this.dui.setMode(m);
    this.updateCorrect();
    * @see setMode
    public int getMode()
    return this.dui.getMode();
    * Use this method to tell this object if it contain semantically correct value. The element
    * itself can't control if semantic is correct. It is responsability of the parent to check
    * semantic of the UIElements value. This method is a way to display that a ArticleNumber is
    * not correct.
    public void setSemanticCorrect(boolean c)
    this.dui.setSemanticCorrect(c);
    this.updateCorrect();
    * @see setSemanticCorrect
    public boolean getSemanticCorrect()
    return this.dui.getSemanticCorrect();
    * This method check if at the moment the uielement is corect at all: syntatically,
    * per range, semantically and requireness.
    * The window can use this method to check if the form can be saved or not.
    public boolean isCorrect()
    return this.dui.isCorrect();
    * This method tell the object to syncronize layout
    * information with the correctness informazion. For example, if
    * the uielement contain a wrong value then after calling this
    * method you are shoure that the background is red(error).
    * <BR>
    * The uiobject itself should call this object at most in this two case:
    * If the lostFocus event fires<BR>
    * If the content of the field is erased.
    // WARNING_COLOR and ERROR_COLOR have priority over
    // EDITABLE_COLOR and NOTEDITABLE_COLOR. (mtm 010327 - UI Bug)
    public void updateCorrect()
    // fire the propertyChange event if necessary before update
    // layout aspect.
    fireUpdate();
    if (isCorrect())
    // (mtm 010327 - UI Bug) Original version.
    // _jtextfield.setEditable(this.isEditable());
    // this.setBackground(_jtextfield.getBackground());
    // this.repaint();
    // Select between EDITABLE and NOTEDITABLE Colors
    setBackground(isEditable() ? EDITABLE_COLOR : NOTEDITABLE_COLOR);
    repaint();
    else
    if (getText().length() == 0)
    // Null object
    setBackground(WARNING_COLOR);
    else
    // Not null object
    setBackground(ERROR_COLOR);
    repaint();
    _setTooltipIfNeeded();
    } // updateCorrect() priority: WARNING_COLOR, ERROR_COLOR */
    * This method tell the object to syncronize layout
    * information with the correctness informazion. For example, if
    * the uielement contain a wrong value then after calling this
    * method you are shoure that the background is red(error).
    * <BR>
    * The uiobject itself should call this object at most in this two case:
    * If the lostFocus event fires<BR>
    * If the content of the field is erased.
    // In this version EDITABLE_COLOR and NOTEDITABLE_COLOR have priority over
    // WARNING_COLOR and ERROR_COLOR.
    public void updateCorrect()
    // fire the propertyChange event if necessary before update
    // layout aspect.
    fireUpdate();
    if (isEditable())
    if (isCorrect())
    setBackground(EDITABLE_COLOR);
    else
    setBackground(getText().length() == 0 ? WARNING_COLOR : ERROR_COLOR);
    else
    setBackground(NOTEDITABLE_COLOR);
    repaint();
    _setTooltipIfNeeded();
    } // updateCorrect() priority: EDITABLE_COLOR, NOTEDITABLE_COLOR/*
    * Overriden setEditable to set editable or not editable Background colors
    * (mtm 010327 - UI Bug)
    public void setEditable(boolean ed)
    super.setEditable(ed);
    // EDITABLE_COLOR and NOTEDITABLE_COLOR have priority over
    // WARNING_COLOR and ERROR_COLOR
    //setBackground(ed ? EDITABLE_COLOR : NOTEDITABLE_COLOR);
    //repaint();
    * Method from FocusListener interface.
    public void focusGained(FocusEvent e)
    System.out.println("show caret");
    setEditable(true);
    Caret caret = getCaret();
    System.out.println(caret);
    caret.setVisible(true);
    //moveCaretPosition(getText().length());
    enableInputMethods(true);
    * Method from FocusListener interface.
    public void focusLost(FocusEvent e)
    // Control if it is all ok
    // Format the field
    if (!e.isTemporary())
    // Make automatic completition when the user leave the field
    enter();
    public void processKeyEvent(KeyEvent e)
    char newKey = e.getKeyChar();
    if (_onlyUpperCase)
    newKey = Character.toUpperCase(e.getKeyChar());
    super.processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), newKey));
    e.consume();
    public void keyTyped(KeyEvent e)
    public void keyPressed(KeyEvent e)
    if (e.getKeyCode() == e.VK_F9)
    if (this.dui.getLOV() != null)
    this.dui.getLOV().addActionListener(this);
    this.dui.getLOV().start(this);
    public void keyReleased(KeyEvent e)
    public void actionPerformed(ActionEvent ae)
    if (ae.getSource() == this)
    enter();
    else
    this.dui.getLOV().removeActionListener(this);
    if (this.dui.getLOV().getValue() != null)
    javax.swing.FocusManager.getCurrentManager().focusNextComponent(this);
    dui.fireEditingCompleted(this);
    //--------------- controlla dimensione del testo... mi sembra pesantuccio!-----------------//
    // FontMetrics fm = this.getGraphics().getFontMetrics(this.getFont());
    FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(this.getFont());
    private void _setTooltipIfNeeded()
    String text = this.getText();
    int tWidth = fm.stringWidth(text);
    int cWidth = this.getSize().width;
    if(tWidth>cWidth && cWidth>0)
    this.setToolTipText(text);
    else
    this.setToolTipText(null);
    * JTextField setText method redefined to perform validation.
    public void setText(String text)
    if (_onlyUpperCase && text !=null)
    text = text.toUpperCase();
    super.setText(text);
    if ((this.getLOV() != null))
    if (this.getLOV().isWorking())
    return;
    updateCorrect();
    setCaretPosition(0);
    dui.fireEditingCompleted(this);
    * Sets the current text.
    public void setValue(String text)
    setAsText(text);
    * Returns the current text.
    public String getValue()
    return getAsText();
    public void setAsText(String text)
    this.setText(text);
    public String getAsText()
    String ret = this.getText();
    if (_onlyUpperCase)
    ret = ret.toUpperCase();
    return PString.trim(ret);
    public void setLOV(LOVWindow lw)
    this.dui.setLOV(lw);
    this.updateCorrect();
    public LOVWindow getLOV()
    return this.dui.getLOV();
    public Dimension getMinimumSize()
    if (_preferredSize == null)
    _preferredSize = super.getPreferredSize();
    return _preferredSize;
    public Dimension getPreferredSize()
    if (_preferredSize == null)
    _preferredSize = super.getPreferredSize();
    return _preferredSize;
    public void setColumns(int colno)
    // invalidate cached data
    super.setColumns(colno);
    _preferredSize = null;
    private void fireUpdate()
    boolean oldSemanticCorrect = this.dui.getSemanticCorrect();
    this.dui.setSemanticCorrect(true);
    boolean correct = this.isCorrect();
    this.dui.setSemanticCorrect(oldSemanticCorrect);
    if ((correct == false) && (this.getAsText().trim().length() != 0))
    return;
    String localOldText = this._oldText;
    this._oldText = this.getAsText();
    firePropertyChange(PhoenixUIElement.ASTEXT_PROPERTY_NAME,localOldText,this._oldText);
    * Inform the component that the editing is completed.
    public void enter()
    if ((this.getMode() == PhoenixUIElement.LOOKUP) && (this.getLOV() != null) && (this.getAsText().length() != 0))
    this.getLOV().isCorrectAuto(this);
    updateCorrect();
    dui.fireEditingCompleted(this);
    * This event is common to all uielement. The event editingCompleted is
    * fired each time the editing reach a complete form. Each swing ui element
    * has a different event to inform that the editing is completed: actionPerformed
    * on the JText, ItemSelected on the JList, focusLost to all elements.
    * <P>
    * <PRE><CODE>
    * actionPerformed focusLost itemsSelected ... enter()
    * \ | / /
    * \ | / _________/
    * \ | / ______/
    * editingCompleted <---------------- setAsText()
    * |
    * |
    * setRequired() ---> updateCorrect
    * setMode() ------/ |
    * |
    * |
    * propertyChange (ASTEXT)
    * </CODE></PRE>
    * Each specific event is mapped on the editingCompleted event. The editing
    * complete event fires an updateCorrect method's call. The updateCorrect
    * fires a propertyChange event if, and only if, the content of
    * the ui element is changed.
    public void addEditingListener(EditingListener ee)
    dui.addEditingListener(ee);
    * Removes the editingListener.
    public void removeEditingListener(EditingListener ee)
    dui.removeEditingListener(ee);
    * This method can be used as common way to set the value for
    * the ui element throught an object. If the object is of the
    * wrong type (like Date for a numeric) no set is made.
    public Object getAsObject()
    return this.getAsText();
    * Return the value in the field as object. For example UIDate return
    * a date object, UINumeric a Double object, UICheckBox a Boolean object, ecc.
    public void setAsObject(Object o)
    if (o instanceof String)
    this.setAsText((String)o);
    * Returns true if the editor is empty. False otherwise.
    public boolean isNull()
    return (this.getAsText().length() == 0);
    * Return the component associated with this editor. In the most cases
    * this is returned.
    public Component getComponent()
    return this;
    public String format(Object o, String pattern)
    return o.toString();
    public String format(Object o, String pattern, Locale l)
    return o.toString();
    public Object parse(String text) throws ParseException
    return text;
    public Object parse(String text, Locale l) throws ParseException
    return text;
    public String getPattern()
    return "";
    public int getAlignment()
    return JLabel.LEFT;
    public Object clone()
    UIText clone = new UIText();
    clone.setText(getText());
    return clone;
    try
    catch (CloneNotSupportedException cnse)
    throw new RuntimeException("Clone not supported?");
    private boolean _noFirePropertyChange = false;
    public void addNotify()
    _noFirePropertyChange = true;
    super.addNotify();
    _noFirePropertyChange = false;
    protected void firePropertyChange(String propertyName,Object oldValue,Object newValue)
    if (!_noFirePropertyChange)
    //System.out.println("NO!");
    if (propertyName.equals("ancestor"))
    return;
    super.firePropertyChange(propertyName, oldValue, newValue);
    public String getMultilangCode()
    return dui.getMultilangCode();
    public String getTooltipMultilangCode()
    return dui.getTooltipMultilangCode();

    Can you explain what are you trying to copy and where?
    Can't you copy text from website to the clipboard or do you have a problem with pasting that text?
    * http://kb.mozillazine.org/Clipboard_not_working

  • Weird problem i have with JTextField

    I have a weird problem with this code...
    if
    JTextField.setText("value")
    then why is
    JTextField.getText() == "value"
    false?
    Can somebody please tell me why this happens....
    The applet below illustrates the problem
    public class help extends javax.swing.JApplet {
    private javax.swing.JTextField Sample;
    public help() {
    initComponents();
    DemonstrateProblem();
    public void DemonstrateProblem()
    System.out.println(Sample.getText());
    if(Sample.getText() == "value")
    System.out.println("This is what you think will happen");
    else
    System.out.println("But instead you end up here");
    System.out.println("Why????");
    private void initComponents()
                   Sample = new javax.swing.JTextField();
                   Sample.setText("value");

    Thanks for the help...
    I didn't realize that by using "==" i was comparing the objects and not the strings they contained.. (did i get that right??)
    anyways i used your suggestion and now it works....
    I am posted my new code for thoose who may want to learn from my mistake
    public class help extends javax.swing.JApplet {
    private javax.swing.JTextField Sample;
         private java.lang.String StrSample;
    public help() {
    initComponents();
    DemonstrateProblem();
    public void DemonstrateProblem()
              System.out.println("This is what Sample =");
    System.out.println(Sample.getText());
              System.out.println("This is what StrSample =");
              System.out.println(StrSample);
    if(StrSample.equals("value"))
    System.out.println("This is what you think will happen");
    else
    System.out.println("But instead you end up here");
    System.out.println("Why????");
    private void initComponents()
                   Sample = new javax.swing.JTextField();
                   Sample.setText("value");
                   StrSample = Sample.getText();

  • SetText()

    ok i have this problem again.... when i call setText() after loading a file (object input stream for jfilechooser) i cant see my text... lets say i have a jtextfield and when i load the file previously saved my jtextfield doesnt update itself from the jtextfield.settext(vector.firstelement());
    do i need to show() or repaint or ...?!?!

    here it is:
    public void LoadDatas()
    loadFile.setDialogTitle("LOAD DATAS"); /*loadFile is a Jfilechooser*/
    int test = loadFile.showOpenDialog(this);
    if(test == JFileChooser.CANCEL_OPTION)
    return ;
    else
    try
    datasVector.clear(); /*datasvector is a vector wich contains my string that i wanna place in the jtextfield*/
    File openDatas = loadFile.getSelectedFile();
    ois = new ObjectInputStream( new FileInputStream(openDatas));
    datasVector.add(ois.readObject());
    rent.setText((String)datasVector.firstElement());
    /*rent is a jtextfield*/
    datasVector.removeElementAt(1);
    }

  • Save ImageIcon to file

    Hello all,
    Could someone teach me to save and ImageIcon class to an file. I've tried ImageIO.write, but that doesn't accept an ImageIcon class. Tried to use BufferedImage, but that doesn't accept ImageIcon either.
    ImageIcon icon = new ImageIcon(file.getAbsolutePath(), "Test");
    int h = icon.getIconHeight();
    int w = icon.getIconWidth();
    int hnew, wnew;
    if (h > w) {
         hnew = jLabelPict.getHeight();
         wnew = w / (h / jLabelPict.getHeight());
    } else {
         wnew = jLabelPict.getHeight();
         hnew = h / (w / jLabelPict.getHeight());
    Image img = icon.getImage().getScaledInstance(
                                  wnew, hnew, Image.SCALE_FAST);
    icon.setImage(img);
    jLabelPict.setIcon(icon);
    jLabelPict.setText("");
    jTextField.setText(file.getAbsolutePath().toString());
    At this point the file should be saved.
    Many thanks & regards

    hope this can works (not tested):
    ImageIcon icon = ...;
    BufferedImage bimg = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
    bimg.getGraphics().drawImage(icon.getImage(), 0, 0, null);
    ImageIO.write(bimg, "jpeg", file);

  • Problem of getting event in the jTabbedPane

    Hi,
    I have problem to do a jTextField.setText(), or jTextField.getText() from a jTabbedPane.
    I create a jTabbedPane and have 7 jPanel in it. For the fifth jPanel, all jTextField in there works normally, but for the 6th and 7th one, all jTextField in there doesn't work.
    When I call getText(), I can alwys get "", and when I call setText(), I cannot see any update in the jTextField, even I can know that the content is actually changed. However, I can still capture the event on this 6th and 7th panel.
    Thanks for help!
    Nachi

    There seem to be quite a lot of quotes in the example above.
    My guess is that it works in the manual login because the shell does concatenate some of the escape characters.
    In a Java program, you should not need that amount of escaping...
    Regards,
    Ludovic.

  • Mapping DB to GUI

    I am looking for an easy way to map DB fields to GUI fields. My plan is to "setName()" my GUI textFields to the same name as my database fields. That gives me an easy way to get the DB field name and value from the GUI; for example....
    JTextField.setName("dbField1");
    JTextField.setText("hello");
    Then I could construct the SQL statement to update the database by getting appropriate db column names and values by using...
    GUIField1.getName();
    GUIFeild1.getText();
    Simple. However, now I need to update the GUI from the database. I can already get column name and value from the resultSet. What is the best way to then update the appropriate GUI field?
    For example, column 1 of the result is named "dbField1" and the value is "hello"
    How can I get the appropriate GUI component (a TextField) inorder to update it?
    I think that I need to do something like... and I am just guessing here.......
    getComponentFor("dbField1").setText("hello");
    Any suggestions????
    thanks

    If you're trying to dynamically build a gui (which it sounds like) then use an array of textfields and labels. Then you can loop through all your fields setting the names and text values of the textfields and labels as you see appropriate.

  • CLEAR FIELDS

    HELLO!
    I HAVE A JFRAME WITH MANY JTEXTFIELDS AND I'D LIKE TO KNOW IF THERE IS AN AUTOMATIC WAY OF DELETING THEIR CONTENT OR SHOULD I DO:
    JTextField.setText("");
    FOR EACH OF THEM ???
    THANKS!!
    NILDA

    If all of you textfields are in the same top-level component (like a window or frame) then write a method which recursively enters each java.awt.Container object and examines its children. Look for javax.swing.text.JTextComponent instead of JTextField, that way if you have a JTextArea or other subclass, it will be covered as well. Each time you find one, call the setText("") method on it. This would be the easiest way to go, unless you have an explicit collection of all the fields already...

  • JFileChooser hangs around

    Hi,
    I have a JFileChooser so I can choose a file... but then I do some processing during the course of which the JFrame, JPanel etc. fields are meant to be updated. But JFileChooser just won't go away and return focus/control/whatever to the main Objects in my program (i.e. JFrame etc.). So the fields only get updated at the end of the processing, at which time the Jfilechooser also goes away.
    I have tried so many things to try and get rid of it: grabfocus, setVisible, disable, etc. etc. But I just can't get rid of it when it's done its job!
    any help much appreciated
    Mike

    if so, the problem is that your swing event loop is busy doing the processing of the file that is picked by the JFileChooser.
    to fix this, simply kick off your processing in it's own thread. and then if you want your thread to update the JFrame then you will need to use the SwingUtilities.invokeLater(runnable) method. to do that, you create little Runnables that have a reference to the item you want to update, such as a TextField and you would put the update in there, such as jTextField.setText("something");

  • Problem with JUNavigationBAR.

    Dear all,
    I developed a frame. In that there is a field of date. So to make user friendly form I have placed a button. For button press i have added the functionality of calendar into it. So when the user presses the button he will get a calendar and then he can change the date. I am now facing a problem. When user selects the date, it will be updating to text field. so for so good. But JUNavigationBar is not at all activating for comitting the data.
    Can any one help me in this regard, Last date for submitting the project is very near.

    Take a look at both threads:
    I think that the first one has your answer.
    Help: JClient bound JTextField.setText doesn't change model?
    URGENT: JClient JTextField Model gets updated only on back tab!
    Regards
    Fred

  • Button event handling JFrame

    I have created a code on NETBEANS IDE contains JFrame that holds some jTextfields and some buttons
    for a certain button I wanted it to add a panel over the same frame contains JTextFields and JComboBoxes, I've written the following code in the implementing method for this button
    private void addActionPerformed(ActionEvent evt)
    JPanel panel = new JPanel();
    panel.getContentPane().add(new JButton("job list");
    panel.getContentPane().add(new JTextField());
    JTextField.setText("job description");
    revalidate();
    repaint();
    but when it executes, nothing appeared on the JFrame, how I could make this work to add as many panels on the same frame each time I pressed that add button
    please, I want the answer as it facilitate my job working on the NETBEANS as the desired layout is got for the created panel.
    the main method exists in other class called joblistTest which declares the first class object
    thank you for your time to the best forum ever for java
    Edited by: Mohamad Samy on Apr 21, 2013 8:39 PM

    Mohamad Samy wrote:
    the method is correct,With respect to the ActionListener Interface: no.
    it is generated automatically by NETBEANS and couldn't be modifiedI'ts hard to beleve either one of this statement.
    also, the program is compiled without any errorsThis I do beleve.
    but when clicking the add button nothing appeared on the JFrame.
    the following code is generated in initComponent() at the class constructor
    addJobButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    addJobButtonActionPerformed(evt);
    then the following method is generated to write my handling code but in vain
    private void addJobButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:
    I want what code to be written in this method, so each time I press the add button the needed buttons and textfields are obtained in the same JFrameWhat prevents you from doing so?
    At first you should replace the comment with a log output, to see that you'r really getting here.
    If this is aproved add more Code to create the desired functionality.
    bye
    TPD

  • Problem Exporting .Jar Using Eclipse

    I have a small problem of exporting using Eclipse 3.2
    First , i could , debug , run as application with no problem.
    however after i compiled into jar , and i tried opening the jar file
    theres no responses. what could possibly be the problem ?
    my manifest file includes the main class of program and all external .jar files.
    below is my main class
    -automatic batch printing
    -able to select target folder for batch printing
    -able to select interval for printing
    -able to stop printing
    -includes log of activity of threads and printing services
    -free for all to use =D
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Desktop;
    import java.awt.Graphics;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import java.io.*;
    import java.util.*;
    import java.util.Timer;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import javax.swing.filechooser.FileFilter;
    import javax.print.*;
    import java.lang.Object;
    import java.awt.JobAttributes.*;
    import javax.swing.text.*;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.rtf.*;
    import java.awt.Dimension;
    import javax.swing.JEditorPane;
    import java.awt.Rectangle;
    import javax.swing.JOptionPane;
    import javax.swing.JScrollPane;
    import javax.swing.JButton;
    import javax.swing.JTextPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JCheckBox;
    import javax.swing.JLabel;
    import javax.swing.SwingUtilities;
    import java.awt.Font;
    public class Test extends JFrame implements Printable{
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;  //  @jve:decl-index=0:visual-constraint="36,9"
         private JButton Open = null;
          Date date;
           class MyFilter extends javax.swing.filechooser.FileFilter {
                 public boolean accept(File file) {
                     String filename = file.getName();
                             if(file.isDirectory()){
                          return true;
                     }else{
                          return filename.endsWith(".rtf");
                 public String getDescription() {
                     return "Rich Text Format ( .rtf ) ";
         public Test() {
              super();
              initialize();
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        Test application = new Test();
                        application.show();
                        application.setLocationRelativeTo(null);
                        application.setVisible(true);
                        application.getJContentPane().setVisible(true);
         private void initialize() {     
              this.setSize(408, 282);
              this.setResizable(false);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setContentPane(getJContentPane());
              this.setTitle("Auto Print Utility");
              this.setVisible(true);
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jLabel1 = new JLabel();
                   jLabel1.setBounds(new Rectangle(131, 102, 59, 16));
                   jLabel1.setFont(new Font("Apple Chancery", Font.PLAIN, 10));
                   jLabel1.setText("MilliSeconds");
                   jLabel = new JLabel();
                   jLabel.setBounds(new Rectangle(16, 103, 53, 16));
                   jLabel.setText("Interval :");
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getOpen(), null);
                   jContentPane.add(getStop(), null);
                   jContentPane.add(getJTextField(), null);
                   jContentPane.add(getJScrollPane(), null);
                   jContentPane.add(getJScrollPane1(), null);
                   jContentPane.add(getJTextField1(), null);
                   jContentPane.add(jLabel, null);
                   jContentPane.add(jLabel1, null);
                   jContentPane.add(getJButton(), null);
              return jContentPane;
         static void printPrinterJob() {               
                    PrinterJob printerjob = PrinterJob.getPrinterJob();
                    // set the characteristics of
                    // the job to be printed - use setPageable and book if
                    // outputing a document. Use setPrintable for "simple" printing - all pages formatted the same
                    printerjob.setPrintable(new Test());
                    try {
                      PrintService[] ser =PrinterJob.lookupPrintServices();
                         ReadRegistry rr = new ReadRegistry();
                     int x =ser.length;
                      //  String def = rr.getPrinter();
                     String def ="Microsoft Office Document Image Writer";
                     for(int y=0;y<x;y++){
                         if(ser[y].getName().equals(def)){
                             printerjob.setPrintService(ser[y]);
                             System.out.println(ser[y]+" SET");
                         }else
                     System.out.println(ser[y]);
                    } catch (PrinterException exception) {
                       System.err.println("Printing error: " + exception);
       public static void disableDoubleBuffering(Component c) {
                  RepaintManager currentManager = RepaintManager.currentManager(c);
                  currentManager.setDoubleBufferingEnabled(false);
      public static void enableDoubleBuffering(Component c) {
                  RepaintManager currentManager = RepaintManager.currentManager(c);
                  currentManager.setDoubleBufferingEnabled(true);
      public boolean printfolder(){
              Desktop de = Desktop.getDesktop();
              java.io.File folder = new File(jTextField.getText());
              File[] listOfFiles = folder.listFiles();
               for (int i = 0; i < listOfFiles.length; i++) {
                    if (listOfFiles.isFile()) {
                        try {
                                  de.print(listOfFiles[i].getAbsoluteFile());
                                  File fi = new File(jTextField.getText()+"\\Deleted");
                                  fi.mkdir();
                                  Thread.currentThread().sleep(1000);
                                  listOfFiles[i].renameTo(new File("Z:\\BTSS Log\\Fax\\Y2007 M10 D25\\Deleted",listOfFiles[i].getName().toString()));
                             } catch (Exception e1) {
                                  // TODO Auto-generated catch block
                                  e1.printStackTrace();
              System.out.println("File: " + listOfFiles[i].getName());
              date = new Date();
              PrintLog.append("Printed : "+listOfFiles[i].getName()+" "+date.toString()+"\n");
              } else if (listOfFiles[i].isDirectory()) {
                   date=new Date();
              System.out.println("Directory: " + listOfFiles[i].getName()+" "+date.toString());
              PrintLog.append("No Files Printed "+date.toString()+"\n");
              return true;
         private JButton Stop = null;
         Thread tt = new Thread(){
              public void run(){
                   while(true){
                   int count = 0; // @jve:decl-index=0:
                   printfolder();
                   try {
                        Long lon = new Long(jTextField1.getText());
                        System.out.println(lon);
              tt.sleep(lon);
              } catch (InterruptedException e) {}
              count++;
              if (count >= 10000) break;
         private JTextField jTextField = null;
         private JScrollPane jScrollPane = null;
         private JScrollPane jScrollPane1 = null;
         private JTextField jTextField1 = null;
         private JLabel jLabel = null;
         private JLabel jLabel1 = null;
         private JTextArea PrintLog = null;
         private JTextArea ThreadLog = null;
         private JButton jButton = null;
         public void run(){
                   while(true){
                   int count = 0;
                   printfolder();
                   try {
              // Thread.sleep (300000);//
                        Long lon = new Long(jTextField1.getText());
                        System.out.println(lon);
              Thread.currentThread().sleep(lon);
              } catch (InterruptedException e) {}
              count++;
              if (count >= 10000) break;
         private JButton getOpen() {
              if (Open == null) {
                   Open = new JButton();
                   Open.setBounds(new Rectangle(11, 38, 187, 29));
                   Open.setText("Start");
                   Open.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             try{
                                  if(jTextField1.getText().equals("")){
                                       JOptionPane.showMessageDialog(null,"MilliSeconds Required, Please Enter A Valid Number Into The TextBox", "MilliSeconds Required", JOptionPane.ERROR_MESSAGE);
                                  }else if(jTextField.getText().equals("")){
                                       JOptionPane.showMessageDialog(null,"Please Specify Directory To Be Print From By Clicking On The TextBox", "Directory Missing", JOptionPane.ERROR_MESSAGE);
                                  }else{
                                       Long.parseLong(jTextField1.getText());
                                       try {     
                                                 if(tt.isAlive()) {
                                                           tt.resume();
                                                           date=new Date();
                                                           ThreadLog.append("Activity Resumes "+date.toString()+"\n");
                                                 } else {
                                                                tt.start();                    
                                                                date=new Date();
                                                                ThreadLog.append("Activity Started "+date.toString()+"\n");
                                                      } catch (Exception f) {
                                                           JOptionPane.showMessageDialog(null, f.getMessage(), "Error Occured", JOptionPane.ERROR_MESSAGE);
                             }catch(Exception f){
                                  JOptionPane.showMessageDialog(null, f.getMessage(), "Long Format Exception", JOptionPane.ERROR_MESSAGE);
              return Open;
         * This method initializes Stop     
         * @return javax.swing.JButton     
         private JButton getStop() {
              if (Stop == null) {
                   Stop = new JButton();
                   Stop.setBounds(new Rectangle(197, 38, 195, 29));
                   Stop.setText("Stop");
                   Stop.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
              try{
         tt.suspend();
         date = new Date();
         ThreadLog.append("Activity Suspend "+date.toString()+" \n");
              }catch(Exception g){
                   JOptionPane.showMessageDialog(null, g.getMessage(), "Error Occured", JOptionPane.ERROR_MESSAGE);
              return Stop;
         public int print(Graphics arg0, PageFormat arg1, int arg2) throws PrinterException {
              // TODO Auto-generated method stub
              return 0;
         * This method initializes jTextField     
         * @return javax.swing.JTextField     
         */JFileChooser jfc = new JFileChooser();
         private JTextField getJTextField() {
              if (jTextField == null) {
                   jTextField = new JTextField();
                   ReadRegistry rr = new ReadRegistry();
                   String dpath = rr.getDirecotry();
                   File file = new File(dpath);
                   jfc.setCurrentDirectory(file);
                   jTextField.setText(dpath);
                   jTextField.setBounds(new Rectangle(11, 14, 383, 20));
                   jTextField.setEditable(false);
                   jTextField.addMouseListener(new java.awt.event.MouseAdapter() {
                        public void mouseClicked(java.awt.event.MouseEvent e) {
                             jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                             jfc.showOpenDialog(jContentPane);
                             File file = jfc.getSelectedFile();
                             String path = file.getAbsolutePath();
                             jTextField.setText(path);
              return jTextField;
         * This method initializes jScrollPane     
         * @return javax.swing.JScrollPane     
         private JScrollPane getJScrollPane() {
              if (jScrollPane == null) {
                   jScrollPane = new JScrollPane();
                   jScrollPane.setBounds(new Rectangle(197, 70, 193, 55));
                   jScrollPane.setViewportView(getThreadLog());
              return jScrollPane;
         * This method initializes jScrollPane1     
         * @return javax.swing.JScrollPane     
         private JScrollPane getJScrollPane1() {
              if (jScrollPane1 == null) {
                   jScrollPane1 = new JScrollPane();
                   jScrollPane1.setBounds(new Rectangle(14, 132, 375, 108));
                   jScrollPane1.setViewportView(getPrintLog());
              return jScrollPane1;
         * This method initializes jTextField1     
         * @return javax.swing.JTextField     
         private JTextField getJTextField1() {
              if (jTextField1 == null) {
                   jTextField1 = new JTextField();
                   jTextField1.setBounds(new Rectangle(70, 101, 62, 20));
              return jTextField1;
         * This method initializes PrintLog     
         * @return javax.swing.JTextArea     
         private JTextArea getPrintLog() {
              if (PrintLog == null) {
                   PrintLog = new JTextArea();
                   PrintLog.setEditable(false);
                   PrintLog.setFont(new Font("Arial", Font.PLAIN, 12));
              return PrintLog;
         * This method initializes ThreadLog     
         * @return javax.swing.JTextArea     
         private JTextArea getThreadLog() {
              if (ThreadLog == null) {
                   ThreadLog = new JTextArea();
                   ThreadLog.setEditable(false);
                   ThreadLog.setFont(new Font("Taffy", Font.PLAIN, 10));
              return ThreadLog;
         * This method initializes jButton     
         * @return javax.swing.JButton     
         private JButton getJButton() {
              if (jButton == null) {
                   jButton = new JButton();
                   jButton.setBounds(new Rectangle(12, 70, 185, 25));
                   jButton.setText("Reset");
                   jButton.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             Test nt = new Test();
                             nt.show();
                             hide();
              return jButton;
    } // @jve:decl-index=0:visual-constraint="-9,-14"
    i can compile into jar successfully but the jar file wouldn't respond.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  

    first , it says unable to access jar file .
    upon deeper inspection i found that background processes is created behind thus the jar file been activated but the UI doesnt show up? any more idea of where my codes gone wrong? which seems perfect for me
    anyway thanks but i still .. it says unable to access jar file

  • Why cann't setText to a JTextField??

    Need your help!
    I produce an array of JTextField and add it to a JPanel.
    But I can only set text when initialized.
    In other place,even I call setText function, it doesn't work.
    Who know the reason??
    thanks in advance!!
    hgs.

    the code is like this:
    public class JFrame {
    JPanel contentPane;
    JPanel panel1 = new JPanel();
    JTextField jt = new JTextField(20);
    JPanel panel2 = new JPanel();
    MyClass class = new MyClass();
    public JFrame(){
    panel1.add(jt);
    panel2.add(class);
    contentPane = (JPanel)this.getContentPane();
    contentPane.add(panel1);
    contentPane.add(panel2);
    class MyClass{
    public MyClass(){
    // here if I call setText,It will work
    // jt.setText("test");
    public otherFunction(){
    // here ,it dosen't work
    jt.setText("test"); // it throw no exception when running

Maybe you are looking for

  • System Image Restore in Window 8.1

    I have not been able to find a data migration application that works at cloning a Windows 8.1 hard drive to a new SSD.  With that in mind I want to go about moving the contents, data and operating system from my working C: to a new SSD.  I want to go

  • Created by and modified by for a item

    when we create a list item we can change the created by and modified by like this : item["Author"] = userValue ; //InternalName of "Created By" field is "Author" item["Editor"]=userValue ;  //InternalName of "Modified By" field is "Editor" but we we

  • Front pannel scroll bar get disabled(not visible)

    Hi,   I am facing some strange problem with Lab View front pannel. I am doing some expriement with PictRing vi which is in Ring&Enum. Then while doing this I lost my scroll bar(both vertical & horizontal) from front pannel. But it's present in block

  • Putting old mail in new user account.

    Hello, Sorry this may be a really simple question, I've had mail running on the administrators account for a couple of years, I'm just creating user accounts for all the different people who use it. I want them all to be able to access the old sent m

  • TS1424 Please help me..I need your help

    How can I solve my ipad....In the first,I want to use my credit then buy something apps then when I click to buy,I can't purchase my credit...there some come up that 'iTunes connot connect to iTunes Store...how can I solve it??