Content of JTextField

Hello All,
I have this problem: With Swing I create a window containig a text field and a button:
// eigene Fensterklasse
class Winster extends JFrame {
// Konstruktor
public Winster (){ 
super("Countdown");
setLocation(200,200);
setSize(300,200);
addWindowListener(new MyWindowListener());
//Panel
JPanel Inhalt = new JPanel();
// Textfeld
JTextField Text = new JTextField(30);
Text.setToolTipText("Pfadname:");
Inhalt.add(Text);
How do I get the Content of the JTextField. I tried Text.getText() but it didn't work.
Thank you in advance.

JTextField Text = new JTextField(30);
using it like that sets the number of columns in the JTextField.
i think you meant
JTextField Text = new JTextField("30");
calling getText() on it now will return "30" which is the text you assigned to it...

Similar Messages

  • How to change the text in JTextField Dynamically

    i am trying to change the contents of JTextField dynamically like this
    textfield.setText();but it is giving error...........how can i do it....

    here is the code .....it is showing error in line 18 and 20 as identifier expected
    their i am trying to make JTextField editable....
    plz have a look
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import javax.swing.SwingUtilities.*;
    import javax.swing.filechooser.FileFilter;
    //import javax.swing.JEditorPane;
    import java.net.URL;
    public class tm extends JFrame implements ActionListener
    public JTextField[] programtext = new JTextField[30];
    public JTextField[] tapetext = new JTextField[30];
    tapetext.setEditable(true);
    public JTextField[] statetext = new JTextField[30];
    statetext.setEditable(true);
    int count =0;
    public static void main (String arg[]){
    tm m=new tm();
    m.setSize(1000,500);
    m.show();
    JButton loadp, run, step,loadi,loads;
    public tm()
    Container c ;
    c = getContentPane();
    c.setLayout(new FlowLayout());
    loadi = new JButton("LOAD INPUT STRING");
    c.add(loadi);
    loadi.addActionListener(this);
    loadi.setBounds(200,25,100,50);
    loadp = new JButton("LOAD PROGRAM");
    c.add(loadp);
    loadp.addActionListener(this);
    loadp.setBounds(300,25,100,50);
    run = new JButton("RUN");
    c.add(run);
    run.addActionListener (this);
    run.setBounds(400,25,100,50);
    step = new JButton("STEP");
    c.add(step);
    step.addActionListener(this);
    step.setBounds(500,25,100,50);
    loads = new JButton("LOAD STATES");
    c.add(loads);
    loads.addActionListener(this);
    loads.setBounds(600,25,100,50);
    JPanel prog = new JPanel();
    prog.setLayout(new GridLayout(30,1));
    for(int i=0;i<programtext.length;i++)
    programtext= new JTextField(10);
    prog.add(programtext[i]);
    JPanel tape = new JPanel();
    tape.setLayout(new GridLayout(30,1));
    for(int i=0;i<tapetext.length;i++)
    tapetext[i]= new JTextField(10);
    tape.add(tapetext[i]);
    JPanel state = new JPanel();
    state.setLayout(new GridLayout(30,1));
    for(int i=0;i<statetext.length;i++)
    statetext[i]= new JTextField(10);
    state.add(statetext[i]);
    JPanel contentPane3 = new JPanel();
    contentPane3.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
    contentPane3.setLayout(new BorderLayout());
    contentPane3.add(state, BorderLayout.CENTER);
    contentPane3.add(c, BorderLayout.NORTH);
    contentPane3.add(prog, BorderLayout.WEST);
    contentPane3.add(tape, BorderLayout.EAST);
    setContentPane(contentPane3);
    public void actionPerformed(ActionEvent e)
    try{
    if(e.getSource ()==loadp)
    JFileChooser chooser=new JFileChooser();
    int r= chooser.showOpenDialog(this);
    if(r==JFileChooser.APPROVE_OPTION )
    String name=chooser.getSelectedFile().getName();
    File f=chooser.getSelectedFile();
    FileInputStream filestream = new FileInputStream(f);
    BufferedInputStream bufferstream = new BufferedInputStream(filestream);
    DataInputStream datastream = new DataInputStream(bufferstream);
    String record = null;
    programtext[0].setText("");
    try { 
    int i = 0;
    while (true)
    record=datastream.readLine();
    if(record == null){
    break;
    programtext[i].setText(record);
    i++;
    count = count + 1;
    System.out.println ("the no of lines of the program are"+ count);
    catch (Exception p)
    System.out.println(p);
    else if(e.getSource()==loads)
    JFileChooser chooser3=new JFileChooser();
    int r3= chooser3.showOpenDialog(this);
    if(r3==JFileChooser.APPROVE_OPTION)
    String name=chooser3.getSelectedFile ().getName();
    File f3=chooser3.getSelectedFile();
    FileInputStream filestream3 = new FileInputStream(f3);
    BufferedInputStream bufferstream3 = new BufferedInputStream(filestream3);
    DataInputStream datastream3 = new DataInputStream(bufferstream3);
    String record3 = null;
    statetext[0].setText("");
    try { 
    int i = 0;
    while (true)
    record3=datastream3.readLine();
    if(record3 == null){
    break;
    statetext[i].setText(record3);
    i++;
    catch (Exception p3)
    System.out.println(p3);
    else if(e.getSource()==loadi)
    JFileChooser chooser2=new JFileChooser();
    int r2= chooser2.showOpenDialog(this);
    if(r2==JFileChooser.APPROVE_OPTION )
    String name=chooser2.getSelectedFile().getName();
    File f2=chooser2.getSelectedFile();
    FileInputStream filestream2 = new FileInputStream(f2);
    BufferedInputStream bufferstream2 = new BufferedInputStream(filestream2);
    DataInputStream datastream2 = new DataInputStream(bufferstream2);
    String record2 = null;
    tapetext[0].setText("");
    try { 
    int i = 0;
    while (true)
    record2=datastream2.readLine();
    if(record2 == null){
    break;
    tapetext[i].setText(record2);
    i++;
    catch (Exception p2)
    System.out.println(p2);
    else if(e.getSource ()==run)
    String temp="";
    String statetemp=" ";
    String tapetemp=" ";
    int l=0;
    int tp=0;
    String pars[][] = new String[50][5];
         for(int m=0;m<count;m++){
    temp = programtext[m].getText();
    String str[]=temp.split(" ");
    for(int k=0;k<5;k++){
    pars[m][k] =str[k];
    System.out.println(pars[m][k]);
    statetemp = statetext[0].getText();
    tapetemp = tapetext[l].getText();
    while(pars[tp][0]==statetemp && pars[tp][1]==tapetemp && tp><count)
         statetemp = pars[tp][2];
         tapetemp = pars[tp][3];
         statetext[0].setText() = statetemp;
         tapetext[tp].setText() = tapetemp;
         if(pars[tp][4]=="R")
         l=l+1;
         else{
         l=l-1;
         tp++;      
    else if(e.getSource()==step)
    catch(Exception t)
    System.out.println(t);

  • Scrollbar doesn't show up on the panel while dynamically adding JTextFields

    I have a dynamic user iterface, where the JTextFields are added dynamically to a JPanel within the JFrame upon the click of a JButton. How do I use the JScrollPane so that the Vertical Scroll bar shows up for the JPanel as soon added TextFields go out of range? The Panel has a null layout coz I want the textfields at specific positions on the panel. The problem lies in showing the Vertical scroll bar once the text fields in the JPanel exceeds the Panel's size. The scrolls don't seem to show up. Please help!
    public Scenario() // Constructor
    textPanel = new JPanel();
    textPanel.setLayout(null);
    textPanel.setSize(508, 520);
    textPanel.setLocation(10,10);
    //..........lines of code
    public void addComponent(String text)
    j = j + 30;
    i = i+1;
    String lineno = Integer.toString(i) + ".";
    field = new JLabel(lineno);
    field.setBounds(90,j,20,24);
    textPanel.add(field);
    if (addline){
    content = new JTextField(text);
    content.setBounds(108,j,400,24);
    content.setBackground(new Color(255,255,255));
    textPanel.add(content);
    addline = false;
    invscenario = false;
    else if(invscenario) {
    content = new JTextField(text);
    content.setBounds(108,j,50,24);
    content.setEditable(false);
    textPanel.add(content);
    try{
    if (content.getText().length()!= 0)
    Statement statement1 = conn.createStatement();
    String query1 = "SELECT * FROM scenario " + "WHERE scenario_num LIKE '" + text + "'";
    rs = statement1.executeQuery(query1);
    rs.next();
    int recordNumber = rs.getInt(1);
    if(recordNumber != 0)
    labelcontent = new JLabel(rs.getString(3));
    labelcontent.setBounds(165,j,100,24);
    textPanel.add(labelcontent);
    }// end try
    catch(SQLException e)
    System.out.println(e);
    invscenario = false;
    addline = false;
    scrollPane = new JScrollPane(textPanel);
    scrollPane.add(textPanel);
    contentPane.add(scrollPane);
    contentPane.repaint();
    show();

    I guess since you don't have a layoutmanager you have to set the viewport dimensions of your JScrollPane manually.
    Try something like
    scrollPane.getViewport().reshape(....);
    zk

  • Error with JTextField

    Hi,
    can anybody tell me why this doesn't work?:
    public class File1 {
    public static void main(String[] args) {
    String Pfad = new String();
    // create Window
    Window1 Dia = new Window1();
    // own Window Class
    class Window1 extends JFrame {
    // constructor
    public Window1 (){ 
    super("Search");
    setLocation(200,200);
    setSize(300,200);
    addWindowListener(new MyWindowListener());
    //Container
    Container conny = getContentPane();
    //Panel
    JPanel Inhalt = new JPanel();
    // Textfeld
    JTextField Getit = new JTextField(30);
    Getit.setToolTipText("Pfadname:");
    Inhalt.add(Getit);
    //Button
    JButton Knopf = new JButton("OK");
    Knopf.addActionListener(new MyActionListener());
    Inhalt.add(Knopf);
    // ContentPane
    conny.add(Inhalt, BorderLayout.NORTH);
    pack();
    show();
    // get content of JTextField
    public String getTextline(){
    return Getit.getText();
    When I try to compile this, I get the error message:
    Undefined variable or class name:Getit
    return Getit.getText();
    ^
    Undefine variable or class name:Dia
    System.out.println(Dia.getTextLine());
    ^
    The second command is used in an ActionListener which I added to
    the button.
    Please help. Whatever I tried, did not work.
    Thank you.
    Ralf

    Sorry for posting this twice.

  • JTextField.getText()

    Hi all,
    I put few JTextFields in an JApplet application. How can I output the content of JTextField? I tried two below but didn't work, it output nothing.
    jtextfield.getText()
    and
    String s = jtextfield.getText()

    Here is critical part of the code:
    public void button_actionPerformed(ActionEvent e)
    if (txtA.getText().equals (""))
    JOptionPane.showMessageDialog(null, "A is missing.", "Invalid Input", JOptionPane.INFORMATION_MESSAGE);
    return;
    if (txtB.getText().equals (""))
    JOptionPane.showMessageDialog(null, "B is missing.", "Invalid Input", JOptionPane.INFORMATION_MESSAGE);
    return;
    int responseAdd = JOptionPane.showConfirmDialog(this, "add A, B?", "Confirmation", JOptionPane.YES_NO_OPTION);
    if (responseAdd == JOptionPane.YES_OPTION)
    resetAandBFields ();
    JOptionPane.showMessageDialog(null, "A, B added successfully", "Information", JOptionPane.INFORMATION_MESSAGE);
    ABRecord addnew = new ABRecord (txtA.getText(), txtB.getText());
    ABRecord has nothing.
    I tried to put the last code "ABRecord addnew = new ABRecord (txtA.getText(), txtB.getText());"
    at the first line just after "public void button_actionPerformed(ActionEvent e)", then it work. I suspect the condition check rotuines have problem.
    Thanks.

  • NullPointerException, how do i get rid of?

    Hey guys,
    I'm totally puzzled by this one. All i'm trying to do is to change the content of JTextField(), but every time i do i get a NullPointerException. Here's the code:
    public class PrivateMessageWindow extends JFrame
        private  Container container;
        private  JTextArea textArea;
        private  JTextField inputField;
        private  String windowId, messageDestination;
        private  Message m;
         public PrivateMessageWindow(String Id)
               super("Private Message");
               Container container = getContentPane();
               JTextArea textArea = new JTextArea();
               textArea.setEditable(false);
               JTextField inputField = new JTextField();
                //ActionListener for inputField
               ActionListener k = new PrivateWindowListener();
               inputField.addActionListener(k);
               //Placement of element on Panel
               container.setLayout(new BorderLayout(5,5));
               container.add(textArea, BorderLayout.CENTER);
               container.add(inputField, BorderLayout.SOUTH);
               //Initializes a message of type private Message
              setSize( 300, 150);
              setVisible(true);
          }//end of constructor
           private class PrivateWindowListener implements ActionListener
                   public void actionPerformed(ActionEvent event)
                        inputField.setText("");
    }// end of  private class PrivateMessageWindowThe problem occurs anytime i access a variable outside the actionPerformed method i get a NullPointerException. I'm not sure if it helps but this class gets triggered by a JButton object.
    any clue of wats happening here?
    Tanx.

    You are not initializing your JTextField inputField. Instead, you instantiate a local variable. The same applies to your JTextArea. You should have:textArea = new JTextArea();
    textArea.setEditable(false);
    inputField = new JTextField();Moreover, I don't think you really need the field container.

  • Rebinding Backspace Key

    Is there anyway to rebind the backspace key so that it does something else other than what it is supposed to do (i.e. delete the character before the current carat position). I've tried doing the inputMap()/actionMap() method to rebind and it fails to stop backspace from deleting the character before the current carat position.

    A much easier way of not deleting is to use a custom Document, but I assumed you wanted delete to still work correctly. I found [url http://forum.java.sun.com/thread.jsp?forum=31&thread=304562]this and tried it and it worked. I have no idea why.import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
      boolean consume;
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        JTextField jtf = new JTextField("Something");
        jtf.addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent ke) {
            if (ke.getKeyCode()==KeyEvent.VK_BACK_SPACE) consume=true;
          public void keyTyped(KeyEvent ke) {
            if (consume) {
              ke.consume();
              consume=false;
        content.add(jtf, BorderLayout.NORTH);
        setSize(100, 100);
        setVisible(true);
      public static void main(String[] args) { new Test(); }
    }

  • A Swing GUI problem.

    There are a JTextfield for entering an integer, a JButton that can be used to square the integer, and another Textfield to show the result. Two questions:
    1) After typing the integer, I want to enter Enter-key to get the result, instead of pressing the JButton. How to code it in this case?
    2) I want using mouse keys to select, copy and paste the contents in JTextfield. What should I do in my code?

    Assuming your Textfield is called JTextField input = new JTextField(10);
    JTextField output = new JTextField(10);
    private class InputListener implements ActionListener
    public void actionPerformed(ActionEvent evt)
    String text = input.getText();
    int x = Integer.parseInt(text) * Integer.parseInt(text);
    output.setText(" " +x);
    this should work I would imagine. when you press enter it will take whatever is in the input field, square it and put it in the output field.

  • How Jaws works?

    Does anybody know how Jaws works?
    What component will be read by Jaws when it's container becomes active windows?
    For example: JDialog
    Environment: Jaws 7.1, windows xp, jdk1.5 , JAB2.0.1
    1. If dialog just contains a JLabel, nothing will be read.
    2. If u use setFocusable(true) to JLabel, Jaws will read dialog title and two times the content of JLabel.
    3. If dialog contains a JTextField, Jaws will read dialog title and two or three times the contents of JTextField.
    Here the code you can try
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.AbstractAction;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class DialogTest {
         protected JFrame frame = null;
         private static int choice = 1;
         public DialogTest(){
              frame = new JFrame("Just a frame");
              frame.setSize(500, 400);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel panel = new JPanel();
              JButton button1 = new JButton(new MyAction("open dialog"));
              panel.add(button1);
              button1.addKeyListener(new KeyAdapter(){
                   public void keyTyped(KeyEvent e) {                    
                        if(KeyEvent.VK_ENTER == e.getKeyChar()){
                             onOpen();
              frame.getContentPane().add(panel);
              frame.setVisible(true);          
         private void onOpen(){
              JDialog dialog = new JDialog(frame,"Jaws Test Dialog");
              JPanel jp = new JPanel();
              JLabel jl = new JLabel("Will be read by Jaws label");
              JTextField jtf = new javax.swing.JTextField("Will be read by Jaws text field");
              switch(choice){
              case 1:
                   jp.add(jl);
                   break;
              case 2:
                   jp.add(jl);
                   System.out.println(jl.isFocusable());
                   jl.setFocusable(true);
                   break;
              case 3:
                   jtf.setEditable(false);
                   jtf.setBackground(jp.getBackground());
                   jtf.setBorder(javax.swing.BorderFactory.createEmptyBorder());
                   jp.add(jtf);
                   break;
              default :
                   jp.add(jl);
              dialog.getContentPane().add(new JPanel().add(jp));
              dialog.setSize(300, 250);
              dialog.setVisible(true);
         public static void main(String[] args){
              choice = 1;//CHANGE THIS TO TEST DIFFERENT CASE 1 2 3
              new DialogTest();
         class MyAction extends AbstractAction{
              public MyAction(String name){
                   super(name);
              public void actionPerformed(ActionEvent e) {
                   onOpen();
    }Please give your point of view to help me, I am totally confused by this.

    Sorry for resurrecting this 4 year old thread, but I recently encountered the same problem and found a solution.
    You need to
    1. modify the accessible tree to skip the JScrollPane and JViewPort
    2. avoid sending accessible property-changed events from the JEditorPane
    Full details including an example here: [Stack Overflow|http://stackoverflow.com/questions/6684389/jeditorpane-jscrollpane-and-accessibility/6693843#6693843].
    If anyone has any insights into why this works, I would very much appreciate hearing it.
    Best regards,
    Rasmus Faber.

  • Button event handling

    hello!
    i would like to convert this code in order to send the content of JTextField when the user press the
    button "send". how can i do this? is getActionCommand() the right method if i change enterfield.addActionListener
    to button.addActionListener?
    Could you help me please?
    button=new JButton("Send");
    enterfield.addActionListener(
             new ActionListener() {
                // send message
                public void actionPerformed( ActionEvent event )
                   int number=Integer.parseInt(event.getActionCommand());
                   sendDataNow( number );
                   enterField.setText( "" );
             }  // end anonymous inner class
          ); // end call to addActionListener

    I have a feeling that you might be adding the ActionListener to the wrong object. You don't add it to the jtextfield, you add it to the button:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Fubar
        static JButton button;
        static JTextField enterField = new JTextField(12);
        public static void main(String[] args)
            button = new JButton("Send");
            button.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent event)
                    try
                        int number = Integer.parseInt(enterField.getText());
                        sendDataNow(number);
                        enterField.setText("");
                    catch (NumberFormatException e)
                        enterField.setText("");
                        enterField.requestFocus();
                        JOptionPane.showMessageDialog(null,
                            "enterField must contain only integer data",
                            "Data Entry Error", JOptionPane.ERROR_MESSAGE);
            JFrame frame = new JFrame("Foo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(enterField, BorderLayout.NORTH);
            frame.getContentPane().add(button, BorderLayout.CENTER);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        protected static void sendDataNow(int number)
            System.out.println(number);
    }

  • JTextArea with setText

    hi it is sadaf here.....................
    Actually i m picking contents of JTextField using getText and storing into a string getName. next using setText function i wanted to display the Contegnt of getName String into JTextArea....... But after compiling Executing it is not showing any thing there......... Please assist me.......
    inside a button btn_save Listener i m doing this
    public class UserInterface extends JFrame{
         private static final long serialVersionUID = 1L;
         abstract class ActionAdapter implements ActionListener{
         public void actionPerformed(ActionEvent ae){}
    protected Container container;
    protected JTextField t_studentName,t_schoolName;
    protected JTextField t_monthlyFees;
    protected JPanel panel;
    protected JLabel l_studentName,l_schoolName,l_monthlyFees;
    protected JButton btn_save,btn_update,btn_click,btn_delete;
    protected JTextArea nameArea;
    String getName;
    UserInterface(){
         container = new Container();
         container.setLayout(null);
         setSize(500,300);
         panel = new JPanel(null,true);
         setContentPane(panel);
         btn_save = new JButton("save");
         btn_save.setBounds(200,10,70,25);
         panel.add(btn_save);
    ///////////////////////// action Listener for save button/////////////////
    btn_save.addActionListener(new ActionAdapter(){
         public void actionPerformed(ActionEvent ae)     
    ////////////////code for displaying content of getName in textArea///////////
         nameArea.setText(getName);
    ///////////////////////////// Creating JTextArea ///////////////////////////////////
    nameArea = new JTextArea();
         nameArea.setBounds(20,120,150,130);
         panel.add(nameArea);
         l_studentName = new JLabel("student");
         l_studentName.setBounds(10,10,50,25);
         panel.add(l_studentName);
    t_studentName = new JTextField();
         t_studentName.setBounds(70,10,110,25);
         panel.add(t_studentName);
         getName= t_studentName.getText();
    }

    if this is in the constructor
    getName= t_studentName.getText();
    getname wil be whatever is in t_studentName at that time - probably ""
    it is not like Excel's automatic recalculation.
    try changing
    nameArea.setText(getName);
    to
    nameArea.setText(t_studentName.getText());

  • How can i get system time and day

    How can i get the system current time and save it into a variable, then get the current day like wednesday and save it into another variable. Can someone teach me how to set this. thanks
    regards,
    albert

    How can i get the system current time and save it
    into a variable, then get the current day like
    wednesday and save it into another variable. Can
    someone teach me how to set this. thanks
    regards,
    alberti've managed to do this but in gui format hope it suites you.
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class time{
         private Container content;
              private JTextField timeField, dateField;
         public static void main (String[]args){
              time t = new time();
              t.TextClockWindow();
              t.showGUI();
         public void TextClockWindow() {
    // Build the GUI - only one panel
    JFrame frame = new JFrame();
    content = frame.getContentPane();
    timeField = new JTextField(6);
    timeField.setFont(new Font("sansserif", Font.PLAIN, 20));
    dateField = new JTextField(6);
    dateField.setFont(new Font("sansserif", Font.PLAIN, 20));
    content.setLayout(new FlowLayout());
    content.add(timeField);
    content.add(dateField);
    // Create a 1-second timer and action listener for it.
    // Specify package because there are two Timer classes
    javax.swing.Timer t = new javax.swing.Timer(1000,new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Calendar now = Calendar.getInstance();
    int h = now.get(Calendar.HOUR_OF_DAY);
    int m = now.get(Calendar.MINUTE);
    int s = now.get(Calendar.SECOND);
    //String ampm =now.get(Calendar.AM_PM);
    int y =now.get(Calendar.YEAR);
    int mon=now.get(Calendar.MONTH);
    int d=now.get(Calendar.DAY_OF_WEEK);
    dateField.setText(""+y+ ". "+mon+ "."+d);
    timeField.setText("" + h + ":" + m + ":" + s);
    //to dispaly the current date so easily;stvworks
    String rightNow = "" + new Date();
    t.start(); // Start the timer
    }//end constructor
    public void showGUI(){
         JFrame frame = new JFrame("Time Frame.");
              frame.add(content);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
    frame.setResizable(false);
    frame.setVisible(true);

  • Help on Java Applet

    I have a JApplet with a JTextField.
    I need to change the contents of JTextField automatically after a period of time.
    For example, I initialised the JTextField to "NIL".
    Then I need to change it to "OK" after 10sec.
    How?
    May I know how to do it?
    Pls post the codes here.
    Thanks.

    so sorry for not explaining clear enough..i need to
    create an image slider control which the output
    result will b when i scroll e slider, it will move on
    to e next image, meaning the slider control bar will
    control e viewing of the next image..i need to put on
    to e website using java applet.. thank u for ur kind
    attention and precious time of eveyone..You are still using abbreviations. I don't actually know what all the letter e on the page is supposed to be. I am guessing they are meant to be the but I can't even understand how that is an abbreviation. You is spelt with 3 letters not one. Your is spelt with 4 letters not one.
    Be is spelt with 2 letters not one.

  • Beginning Swing programming problem

    My classmates and I are trying to write a simple Swing program with a single button and a text field that contains the number of times the button has been pressed since the program started. The problem is that in the ActionPerformed method, any changes to the text field ends up with multiple event errors. It will print the count fine to the command prompt, but not the GUI. Any insight would be greatly appreciated.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class CounterGUI extends JFrame implements ActionListener
         public int count = 0;
         Container contents = getContentPane();
         JTextField counter;
         final String temp = "Total times pressed: ";
         public CounterGUI()
              final int width = 300;
              final int height = 300;
              setSize(width, height);
              JTextField counter = new JTextField(temp + count);
              counter.setEditable(false);
              JButton clicker = new JButton("Click me!");
              clicker.addActionListener(this);
              clicker.setActionCommand("Click");
              contents.add(counter, "Center");
              contents.add(clicker, "South");
         public void actionPerformed(ActionEvent e)
              String command = e.getActionCommand();
              if(command == "Click")
                   count++;
                   counter.setText(temp + count);     
                   System.out.println(count);
         public static void main(String[] args)
         JFrame f = new CounterGUI();
         f.addWindowListener(new WindowCloser());
              f.setVisible(true);

    Hi Guys,
    The line JTextField counter = new JTextField(temp + count); is declared in the constructor, this means that the field counter is not visible to other methods and you'll get a null pointer exception (NPE) when you try to access the class field counter
    Change to counter = new JTextField(temp + count); Now if you were catching and displaying exceptions you'd notice that this was happening.
    Dave

  • How to right align JTextField content

    Is there a way to right align the content of a JTextField?

    In the JDK1.4.2 API for JTextField, the are 7 methods that start with "set...". It shouldn't be to hard to guess which one would be used for right aligning the contents of the JTextField.

Maybe you are looking for

  • Plant not taking in purchase order

    Hi Frnds, I got a problem while raising PO. In ME21N, after entering all the details, the plant is not taking up even i enter the plant. I have 8 plants and out of that if i press F4, only 2 plants are visible. I have checked in OMS@ for qty and valu

  • RFC sender communication channel

    Hi, I am working on RFC->XI->SOAP scenario. In R/3, I maintainted an RFC destination with program id same as RFC sender CC  in XI, Gateway and host of XI server. But when i test connection the RFC destination, I am getting the following error. /CPIC-

  • Samsung 730B DVI Connection

    Hello - I am purchasing a Samsung 730B 17" LCD monitor. It has both RGB/DVI and i am curious will the DVI work with my stock standard PowerMac G4 FW800 with mirrored doors. What type of cable would I have to get as I know there are different flavours

  • API to load suppler in oracle apps 11.5.10.2

    Hi, Can anyone tell, is there any API to load supplier in oracle apps 11.5.10.2? Thanks In Advance, RR

  • I have installed flash player on my macbook air but some videos still don't play, what can i do?

    i have installed flash player on my macbook air but some videos still don't play, what can i do?