JTextArea append problem

I have the following problem:
I am creating a JFrame with a JTextArea in it.
After all components are added to the JFrame
I call:
setLocation(100, 100);
pack();
setVisible(true);
Then a method is called that generates files and uses
jTextArea.append(".");
to add a "." to the JTextArea for each created file
to show the progress.
Now the problem is that the dots are not shown one after the other.
The window pops up AFTER all the dots are written and not when
setVisible(true);
is called.
What do I have to do that every single dot is shown in the
JTextArea right after it is appended ?

Move your actual file generating process to a different thread. The best way to do it is using SwingWorker. There is a tutorial on the Sun's web site at http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html that demonstrates how to use SwingWorker.
Hope this helps
Sai Pullabhotla

Similar Messages

  • Question on JTextArea.append(String str)

    Hi All,
    When i provide JTextArea.append("FMTL") it is showing me on the JTextArea but when i give it as
    String item="Viswanadh";
    JTextArea.append(item).this particular statement is remaming blank on the TextArea.
    Any idea why this is happening and is there any other method to be used instead of append.???
    Thanks in advance..
    regards,
    Viswanadh

    class OnApplyFormat implements ActionListener{
         public void actionPerformed(ActionEvent formatevent){
              JComboBox source = (JComboBox) formatevent.getSource();
                   String item =  source.getSelectedItem().toString();
                     System.out.println("Selected Format is:"+item);
                     try
                       if ( item!=null )
                              System.out.println("Format is:"+item);
                     infoarea.append("FMTL");
                   infoarea.append(item);
                     infoarea.append("\r\n");
                   infoarea.append("FMTU");
                   infoarea.append("\r\n");
                   infoarea.append("wait 5");
                   infoarea.append("\r\n");
              else
                   throw new Exception("FormatNotFoundException");
                          }catch(Exception e){
                          e.printStackTrace();
    }That is my code and still i am facing the same FMTL is not getting appended with the item variable.
    Help me in solving this issue.
    Thanks in advance.
    regards,
    Viswanadh

  • JTextArea.append

    I have got some problem using the .append method of the JTextArea class. Below is my statement.
    The declaration
    private JTextArea ulist;
    ulist = new JTextArea();
    ulist.setFont(new Font("Tahoma", 0, 11));
    ulist.setEnabled(false);
    JScrollPane spulist = new JScrollPane(ulist);
    spulist.setLocation(24, 285);
    spulist.setSize(187, 150);
    con.add(spulist);
    spulist.append("Client" + clientno + "'s host name is" inetAddress.getHostName() "\n");
    The error message i got was " cannot find symbol method in java.lang.string"
    Can anyone help?

    try ulist.append() rather than spulist.append. it
    might workYes I rather think it will. I was hoping in reply 1 that the OP would spot the error of their ways with just a hint.

  • Combo and append problems

    Hi. 3 problems here
    1 - string of provinces not showing in combo box instead shows
    [Ljava.lang.stringj@1950198
    2- says I can't append to jta.append ? was able to use similar coding in other programs
    3- how to append from jcb to text area
    code not working has // before
    package second;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    //import java.awt.event.ActionEvent;
    public class Exercise11_7 extends JFrame
      implements ActionListener {
       String province[] = {"BC","AB","SK","MN","ON","QB","NB","NS","NF","PI","YK","NT","NV"};
      private JTextField jtfName;
      private JTextField jtfDepartment;
      private JTextField jtfUniversity;
      private JTextField jtfCity;
      private JTextField jtfZip;
      private JComboBox jcb;
      private JTextArea jta;
      private JButton jbtStore;
      public static void main(String[] args) {
        JFrame frame = new Exercise11_7();
        frame.setSize(300, 200);
        frame.setTitle("Exercise 11.7");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
      public Exercise11_7() {
        JPanel p = new JPanel();
        p.setLayout(new GridLayout(3,1,5,5 ));
        p.add(new JLabel("Name"));
        p.add(jtfName = new JTextField(null));
        p.add(new JLabel("Department"));
        p.add(jtfDepartment = new JTextField(15));
        p.add(new JLabel("University"));
        p.add(jtfUniversity = new JTextField(12));
        JPanel p2 = new JPanel();
        p2.setLayout(new GridLayout(1,3 ));
        p2.add(new JLabel("City"));
        p2.add(jtfCity = new JTextField(null));
        p2.add(new JLabel("Zip"));
        p2.add(jtfZip = new JTextField(8));
        p2.add(new JLabel("Province"));
        p2.add(jcb = new JComboBox());
        JPanel p3 = new JPanel();
        p3.setLayout(new GridLayout(1,2 ));
        p3.add(jta = new JTextArea(4,10));
        p3.add(jbtStore = new JButton("Store"));
        // Add the panel and a button to the frame
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(p, BorderLayout.NORTH);
       // getContentPane().add(jbtStore = new JButton("Store"), BorderLayout.EAST);
        getContentPane().add(p2,FlowLayout.LEFT);
        getContentPane().add(p3,BorderLayout.SOUTH);
         //jbtStore.addActionListener(this);
        // Register listener
        jcb.addActionListener(this);
        jcb.addItem("NS");//just to see if working
       for (int i =0;i<province.length;i++){
       jcb.addItem(province);
       jcb = new JComboBox(province);
        public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();
      String text1 = jtfName.getText();
      String text2 = jtfDepartment.getText();
      String text3 = jtfUniversity.getText();
      String text4 = jtfCity.getText();
    // String text5 = jcb.getText(); 
      String text6 = jtfZip.getText();
        if (e.getSource() instanceof JButton)
        if ("Store".equals(actionCommand)){
      //       jta.append(text1 + "\n",  text2 + "\n", text3 + "\n" , text4, text6 ); }
        jcb = (JComboBox)e.getSource();
        String province = (String)jcb.getSelectedItem();
    //     if (e.getSource().equals(jcb))
       //     jtf.setText5(jcb.getSelectedItem().toString() );
    //somehow add Province to text area

    You can either extend JFrame and call JFrame methods inside the class (which is a JFrame by extension)
    or
    do not extend JFrame and instantiate a JFrame inside the class to show the class.
    But not both.
    The first option is used in your app below.
    Here's the second option:
    public class Exercise
        public Exercise()
            // same component initialization code as before
            JFrame f = new JFrame("Exercise");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(...
            f.setSize(...) or f.pack();
            f.setLocation(200,200);
            f.setVisible(true);
        public static void main(String[] args)
            new Example();
    }You don't need to add an ActionListener to the JComboBox, just read the selection for your data. If you do want one I would not use the same ActionListener as you use for the JButton. Make another ActionListener for the JComoBox; could be an anonymous inner class
        jcb.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                // code here
        });or a nested (named inner class).
    This below runs and looks different than what you posted. I recommend you run it as is to have a look.
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    public class Exercise extends JFrame implements ActionListener {
        String[] province = {
            "BC","AB","SK","MN","ON","QB","NB","NS","NF","PI","YK","NT","NV"
        private JTextField jtfName;
        private JTextField jtfDepartment;
        private JTextField jtfUniversity;
        private JTextField jtfCity;
        private JTextField jtfZip;
        private JComboBox jcb;
        private JTextArea jta;
        private JButton jbtStore;
        public static void main(String[] args) {
            new Exercise();
        public Exercise() {
            JPanel p = new JPanel();
            p.setLayout(new GridLayout(3,1,5,5 ));
            p.add(new JLabel("Name"));
            p.add(jtfName = new JTextField(15));
            p.add(new JLabel("Department"));
            p.add(jtfDepartment = new JTextField(15));
            p.add(new JLabel("University"));
            p.add(jtfUniversity = new JTextField(12));
            JPanel p2 = new JPanel();
    //        p2.setLayout(new GridLayout(1,3 ));
            p2.add(new JLabel("City"));
            p2.add(jtfCity = new JTextField(12));
            p2.add(new JLabel("Zip"));
            p2.add(jtfZip = new JTextField(8));
            p2.add(new JLabel("Province"));
            p2.add(jcb = new JComboBox(province));
            JPanel p3 = new JPanel();
    //        p3.setLayout(new GridLayout(1,2 ));
            p3.add(jta = new JTextArea(4,10));
            p3.add(jbtStore = new JButton("Store"));
            jbtStore.addActionListener(this);
            // Add the panels to the frame
    //        getContentPane().setLayout(new BorderLayout());  // default - not needed
            getContentPane().add(p, BorderLayout.NORTH);
            getContentPane().add(p2);                        // default BorderLayout.CENTER
            getContentPane().add(p3,BorderLayout.SOUTH);
            // call JFrame methods
    //        setSize(300, 200);
            pack();
            setLocation(200,200);
            setTitle("Exercise 11.7");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setVisible(true);
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton)e.getSource();
            String actionCommand = button.getActionCommand();
            if (actionCommand.equals("Store")) {
                String text1 = jtfName.getText();
                String text2 = jtfDepartment.getText();
                String text3 = jtfUniversity.getText();
                String text4 = jtfCity.getText();
                String text5 = (String)jcb.getSelectedItem();
                String text6 = jtfZip.getText();
                jta.append(text1 + "\n" + text2 + "\n" + text3 + "\n" +
                           text4 + ", " + text5 + " " +  text6 );
    }

  • Record appending problem in the flat file

    Hi everybody,
    I am using this code I have to append records one by one(in next line) in a text file, But the records are getting appended side by side how to solve this problem.
    code is like this
    <%
    String varValue="042204ccc";
    String loginID="xxxx";
    String str= varValue+"="+loginID;
    FileWriter fw = new FileWriter(new File("details.txt"),true);
    fw.write(str);
    fw.close();
    %>
    thanks in advance.

    Better yet, append System.getProperty("line.separator"). That's platform independent.
    MOD

  • Doubt to be Clarified on JTextArea appending a string

    Hi All,
    Here is the actual code.
    String msg="Settings Details Will be Produced after the Connection is Successful";
                        String msg1=      "-------------------------------------------------------------------------";
                        String comdetails="1)Comport Enabled is:";
                        String baudratedetails="2)BaudRate Selected is:";
                        String databitdetails="3)DataBit is:";
                        String paritybitdetails="4)ParityBit is:";
                        String stopbitdetails="5)Stopbit is:";
    contentarea.setText("");
                           contentarea.append(msg);
                        contentarea.append("\r\n");
                        contentarea.append(msg1);
                        contentarea.append("\r\n");
                        contentarea.append(msg1);
                        contentarea.append("\r\n");
                        contentarea.append(comdetails);contentarea.append(cv);
                        contentarea.append("\r\n");
                        contentarea.append(baudratedetails);contentarea.append(bv);
                        contentarea.append("\r\n");
                        contentarea.append(databitdetails);contentarea.append(dv);
                        contentarea.append("\r\n");
                        contentarea.append(paritybitdetails);contentarea.append(pv);
                        contentarea.append("\r\n");
                        contentarea.append(stopbitdetails);contentarea.append(sv);
                        contentarea.append("\r\n");
                        contentarea.append(msg1);
                        contentarea.append("\r\n");
                        contentarea.append(msg1);I have a JTextArea which is basically linked up with a JBUtton.So when i click on JButton in the JTextArea thte following will be displayed.
    "Settings Details Will be Produced after the Connection is Successful"
    1)Comport Enabled is:COM3
    2)BaudRate Selected is:38400
    3)DataBit is:8bit
    4)ParityBit is:NONE
    5)Stopbit is:1bitSo my question when i again click on the same JButton the same data which is highlighted in the code tags need to be displayed again from the next end line of the previous data instead of overriding operation.Can any one help me out in doing this???
    Thanks in advance.
    regards,
    Viswanadh

    Hi toodburch,
    Thanks for the reply.My requirement is for every click on the JButton it should be in the following way.Assume i have pressed 3 times.then it should be displayed as shown.
    "Settings Details Will be Produced after the Connection is Successful"
    1)Comport Enabled is:COM3
    2)BaudRate Selected is:38400
    3)DataBit is:8bit
    4)ParityBit is:NONE
    5)Stopbit is:1bit
    "Settings Details Will be Produced after the Connection is Successful"
    1)Comport Enabled is:COM3
    2)BaudRate Selected is:38400
    3)DataBit is:8bit
    4)ParityBit is:NONE
    5)Stopbit is:1bit
    "Settings Details Will be Produced after the Connection is Successful"
    1)Comport Enabled is:COM3
    2)BaudRate Selected is:38400
    3)DataBit is:8bit
    4)ParityBit is:NONE
    5)Stopbit is:1bitThanks
    regards,
    Viswanadh

  • JTextArea output problem

    When i create a text file and then open it back up with the below applcation,
    i get little squares appended to the end of the text.
    the application
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class FileIO extends JFrame implements ActionListener
         JButton btn_open;
         JButton btn_save;
         JButton btn_clear;
         JTextField file_path;
         JTextArea stuff;
          ///  Edited for size  ///
         //Methods
         private void Read_File()
              File input = new File(file_path.getText());
              FileReader reader;
              JDialog msg;
              char[] lines = new char[80];
              try {
                   reader = new FileReader(input);
                   while(reader.read(lines) != -1)
                        stuff.append(new String(lines));
                   reader.close();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
                   msg = new JOptionPane("FILE NOT FOUND ERROR", JOptionPane.ERROR_MESSAGE,
                             JOptionPane.DEFAULT_OPTION).createDialog("ERROR_MESSAGE");
                   msg.setVisible(true);     
              } catch (IOException e) {
                   e.printStackTrace();
                   msg = new JOptionPane("FILE IO ERROR", JOptionPane.ERROR_MESSAGE,
                             JOptionPane.DEFAULT_OPTION).createDialog("ERROR_MESSAGE");
                   msg.setVisible(true);
         private void Write_File()
              File output = new File(file_path.getText());
              FileWriter w;
              JDialog msg;
              try {
                   w = new FileWriter(output);
                   stuff.write(w);
                   w.close();
              } catch (IOException e) {
                   e.printStackTrace();
                   msg = new JOptionPane("FILE IO ERROR", JOptionPane.ERROR_MESSAGE,
                             JOptionPane.DEFAULT_OPTION).createDialog("ERROR_MESSAGE");
                   msg.setVisible(true);
         //ActionListener
         public void actionPerformed(ActionEvent evt)
              Object source = evt.getSource();
              if(source == btn_open)
                   Read_File();
              else if(source == btn_save)
                   Write_File();
              else if(source == btn_clear)
                   stuff.setText("");
            ///  Edited for size  ///
    }

    using sun-jdk 1.6.0.20 on Gentoo 32 bit
    source code:(copy/paste/run)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class FileIO extends JFrame implements ActionListener
         JButton btn_open;
         JButton btn_save;
         JButton btn_clear;
         JTextField file_path;
         JTextArea stuff;
         public FileIO()
              super("FILE IO Example");
              setSize(300, 300);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              GridBagLayout bag_layout = new GridBagLayout();
              setLayout(bag_layout);
              GridBagConstraints c = new GridBagConstraints();
              //TextField file_path
              file_path = new JTextField(40);
              c.fill = GridBagConstraints.HORIZONTAL;
              c.gridx = 0;
              c.gridwidth = 4;
              c.gridy = 0;
              c.gridheight = 1;
              c.weightx = 1.0;
              add(file_path, c);
              //TextArea stuff and JScrollPane scroll
              stuff = new JTextArea(40, 40);
              JScrollPane scroll = new JScrollPane(stuff,
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              c.fill = GridBagConstraints.BOTH;
              c.gridy++;
              c.gridheight = 4;
              c.weighty = 1.0;
              add(scroll, c);
              //JButton btn_open
              btn_open = new JButton("Open File");
              btn_open.addActionListener(this);
              c.fill = GridBagConstraints.HORIZONTAL;
              c.gridy = 5;
              c.gridheight = 1;
              c.gridwidth = 1;
              c.weightx = 1.0;
              c.weighty = 0.0;
              add(btn_open, c);
              //JButton btn_save
              btn_save = new JButton("Save File");
              btn_save.addActionListener(this);
              c.gridx++;
              add(btn_save, c);
              //JButton btn_clear
              btn_clear = new JButton("Clear");
              btn_clear.addActionListener(this);
              c.gridx++;
              add(btn_clear, c);
              setVisible(true);
         //Methods
         private void Read_File()
              File input = new File(file_path.getText());
              FileReader reader;
              JDialog msg;
              char[] lines = new char[80];
              try {
                   reader = new FileReader(input);
                   while(reader.read(lines) != -1)
                        stuff.append(new String(lines));
                   reader.close();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
                   msg = new JOptionPane("FILE NOT FOUND ERROR", JOptionPane.ERROR_MESSAGE,
                             JOptionPane.DEFAULT_OPTION).createDialog("ERROR_MESSAGE");
                   msg.setVisible(true);     
              } catch (IOException e) {
                   e.printStackTrace();
                   msg = new JOptionPane("FILE IO ERROR", JOptionPane.ERROR_MESSAGE,
                             JOptionPane.DEFAULT_OPTION).createDialog("ERROR_MESSAGE");
                   msg.setVisible(true);
         private void Write_File()
              File output = new File(file_path.getText());
              FileWriter w;
              JDialog msg;
              try {
                   w = new FileWriter(output);
                   stuff.write(w);
                   w.close();
              } catch (IOException e) {
                   e.printStackTrace();
                   msg = new JOptionPane("FILE IO ERROR", JOptionPane.ERROR_MESSAGE,
                             JOptionPane.DEFAULT_OPTION).createDialog("ERROR_MESSAGE");
                   msg.setVisible(true);
         //ActionListener
         public void actionPerformed(ActionEvent evt)
              Object source = evt.getSource();
              if(source == btn_open)
                   Read_File();
              else if(source == btn_save)
                   Write_File();
              else if(source == btn_clear)
                   stuff.setText("");
         //Main
         public static void main(String[] args)
              new FileIO();
    }the appended nonprintable characters show up as little squares in the JTextArea, but they do not show up in any file editors on my computer.
    Edited by: grimx on Jul 3, 2010 7:24 PM
    Edited by: grimx on Jul 3, 2010 7:31 PM

  • JTextArea scrolling problem

    Hello!
    I have a JTextArea inside a JScrollPane and i'm sending it lots of text that makes the scrollbars appear when it stops fitting the JTextArea. The thing is the scrollbars don't scroll along with the text, and instead stay put on top of the JTA. If I go to the end of the JTA and hit [ENTER] it starts scrolling beautifuly from that point on. So I always send "\n" at the end of the text to make it scroll. But it doesn't do the trick...
    Is there something i can do to get it going? I've looked at the API but I didn't find anything that solved the problem...
    Thank you very much for your help!

    As you said when u pressed ENTER it scrolls, its mean there is no problem with your JTextArea. Actually, when your Application Executes JTextArea in it, appears without the scrollbars(hor,ver) until you enter text in it at runtime. There is no problem, so work with it .

  • JTextArea Wraping problem!

    Hi, i am using a JTextArea do display diferent length text, this text area is inside a JSplitPane, my problem is that when the text is too wide, the JTextArea does not divide the text in lines, this way, only a part of the text is visible.
    There is a solution, invoke the setLineWrap(TRUE) method, it seems good, but it does not work for me, when i envoke this method the text is not shown......crazy
    anyone....
    thanks

    Try placing the JTextArea inside a JScrollPane

  • StringBuffer.append() problem

    Hi there,
    i got a problem with a StringBuffer-Object i can�t understand...
    Vector fieldVcetor = new Vector();
    //fieldVector saves the fields in form of a string...
    StringBuffer sql = new StringBuffer("SELECT ");
    for(int i = 0; i < fieldVector.size(); i++ )
      sql.append(fieldVector.get(i));
    sql.append(" FROM myTable");
    System.out.println(sql);and not
    "SELECT field1,field2,field3 FROM myTable"
    is given out, only
    " FROM myTable"
    is given out...
    why???
    can anyone help me?
    thx anyway
    Errraddicator

    well, I know this doesn't help you, but I compiled your code (after correcting the "fieldVcetor" typo and adding a field name to the vector) and it emitted the following:
    $ java SBTest
    SELECT Field 1 FROM myTable
    The modified code looked like:
    import java.util.Vector;
    public class SBTest {
         public static void main(String[] args) {
              Vector fieldVector = new Vector();
              fieldVector.addElement(" Field 1 ");
              //fieldVector saves the fields in form of a string...
              StringBuffer sql = new StringBuffer("SELECT ");
              for(int i = 0; i < fieldVector.size(); i++ )
                   sql.append(fieldVector.get(i));
              sql.append(" FROM myTable");
              System.out.println(sql);
    }Good luck
    Lee

  • JMX-Log4j Appender problem

    Dear listers
    we wrote thefollowing code to log the loglevel's dynamically.
    Following is the code
    public class MyApp implements MyAppMBean {     
    private static Logger logger = Logger.getLogger(MyApp.class);
    public void go() throws Exception{
    while(true){
    logger.debug("DEBUG") ;
    logger.info("INFO") ;
    logger.warn("WARN");
    logger.error("ERROR");
    logger.fatal("FATAL");
    Thread.sleep(2000);
    public void setLoggingLevel(String level){
    logger.info("Setting logging level to: " + level);
    Level newLevel = Level.toLevel(level, Level.INFO);
    Logger.getRootLogger().setLevel(newLevel);
    public String getLoggingLevel(){                       
    return Logger.getRootLogger().getLevel().toString() ;
    public static void main(String[] args) throws Exception
    DOMConfigurator.configure("log4j.xml");
    MyApp app = new MyApp();
    //Lookup for the mbean server
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    //Create and register the top level log4j MBean
    HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
    ObjectName mbo = new ObjectName("log4j:logger=root");
    System.out.println("Debug10");
    server.registerMBean(hdm, mbo);
    LoggerRepository r = LogManager.getLoggerRepository();
    Enumeration<Logger> elogs = r.getCurrentLoggers();
    Logger logger = null;
    while(elogs.hasMoreElements())
    //need to show the elements of teamcenter only.
    logger = (Logger)elogs.nextElement();
    hdm.addLoggerMBean(logger.getName());
    } System.out.println(Logger.getRootLogger().getLevel().toString());
    int portNumber=9999;
    ObjectName htmlName = new ObjectName("log4j:logger=root,port=" + portNumber) ;
    HtmlAdaptorServer html = new HtmlAdaptorServer(portNumber);
    html.setPort(portNumber);
    server.registerMBean(html, htmlName);
    html.start();
    app.go();
    When setting the attributes for the appenders under log4j from htmladapter it gives the following message.
    *477 All Attributes Not Set*
    *1/8 attribute(s) were not set:*
    appender%3DTaskAppender%2Clayout%3Dorg.apache.log4j.PatternLayout
    Please advice how can we solve this issue ~Vilas

    Dear listers
    we wrote thefollowing code to log the loglevel's dynamically.
    Following is the code
    public class MyApp implements MyAppMBean {     
    private static Logger logger = Logger.getLogger(MyApp.class);
    public void go() throws Exception{
    while(true){
    logger.debug("DEBUG") ;
    logger.info("INFO") ;
    logger.warn("WARN");
    logger.error("ERROR");
    logger.fatal("FATAL");
    Thread.sleep(2000);
    public void setLoggingLevel(String level){
    logger.info("Setting logging level to: " + level);
    Level newLevel = Level.toLevel(level, Level.INFO);
    Logger.getRootLogger().setLevel(newLevel);
    public String getLoggingLevel(){                       
    return Logger.getRootLogger().getLevel().toString() ;
    public static void main(String[] args) throws Exception
    DOMConfigurator.configure("log4j.xml");
    MyApp app = new MyApp();
    //Lookup for the mbean server
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    //Create and register the top level log4j MBean
    HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
    ObjectName mbo = new ObjectName("log4j:logger=root");
    System.out.println("Debug10");
    server.registerMBean(hdm, mbo);
    LoggerRepository r = LogManager.getLoggerRepository();
    Enumeration<Logger> elogs = r.getCurrentLoggers();
    Logger logger = null;
    while(elogs.hasMoreElements())
    //need to show the elements of teamcenter only.
    logger = (Logger)elogs.nextElement();
    hdm.addLoggerMBean(logger.getName());
    } System.out.println(Logger.getRootLogger().getLevel().toString());
    int portNumber=9999;
    ObjectName htmlName = new ObjectName("log4j:logger=root,port=" + portNumber) ;
    HtmlAdaptorServer html = new HtmlAdaptorServer(portNumber);
    html.setPort(portNumber);
    server.registerMBean(html, htmlName);
    html.start();
    app.go();
    When setting the attributes for the appenders under log4j from htmladapter it gives the following message.
    *477 All Attributes Not Set*
    *1/8 attribute(s) were not set:*
    appender%3DTaskAppender%2Clayout%3Dorg.apache.log4j.PatternLayout
    Please advice how can we solve this issue ~Vilas

  • JTextArea setLocation problem?

    The JTextArea setLocation method is not sticking after the call to repaint(). The JTextArea is going back to it's original location; the repaint() method is acting like the pack() method.
    I've written a test application to show what I'm talking about. (The test Application is in two files.)
    The following program draws a circle and has 5 JTextAreas, you can drag the text areas anywhere on the screen. On the repaint() method call the text areas get reset to their original positions. If you remark the repaint() calls out the text areas stay where you place them. Try to place one of the text areas over the circle with and without the repaint calls commented out, the circle gets erased. This is why I need to call repaint.
    This behavior only occurs if the following program is an application. The setLocation method works fine if this is placed in an Applet. This behavior was discovered when I tried to make my Applet an Application. If anyone can provide a work around I'd appreciate it.
    Thanks,
    Andrew
    package test;
    import java.awt.Toolkit;
    import javax.swing.*;
    import javax.swing.UIManager;
    import java.awt.Dimension;
    public class Test {
    boolean packFrame = false;
    public static void main(String[] args) {
    JFrame frame = new Frame1();
    frame.setTitle("Application");
    frame.setSize(600, 550);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation( (d.width - frame.getSize().width) / 2,
    (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(3);
    frame.setResizable(false);
    ---------------------New File---------------------------
    package test;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseEvent;
    import javax.swing.border.LineBorder;
    public class Frame1
    extends JFrame implements MouseMotionListener {
    Image aFrame = null;
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();
    JLabel statusBar = new JLabel();
    JTextArea[] display = null;
    JPanel centerPanel = null;
    JPanel moviePanel = null;
    public Frame1() {
    try {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    jbInit();
    catch (Exception exception) {
    exception.printStackTrace();
    private void jbInit() throws Exception {
    contentPane = (JPanel) getContentPane();
    contentPane.setLayout(borderLayout1);
    setSize(new Dimension(400, 300));
    setTitle("Frame Title");
    statusBar.setText(" ");
    contentPane.add(statusBar, BorderLayout.SOUTH);
    centerPanel = new JPanel(new BorderLayout());
    moviePanel = new JPanel(new GridBagLayout());
    display = new JTextArea[5];
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx=gbc.RELATIVE;
    gbc.gridy=gbc.RELATIVE;
    for (int i=0; i < display.length; i++) {
    display[i] = new JTextArea(" ",3,15);
    moviePanel.add(display, gbc);
    display[i].setBorder(new LineBorder(Color.lightGray));
    display[i].addMouseMotionListener(this);
    centerPanel.add(moviePanel, BorderLayout.CENTER);
    contentPane.add(centerPanel, BorderLayout.CENTER);
    moviePanel.addMouseMotionListener(this);
    centerPanel.addMouseMotionListener(this);
    contentPane.addMouseMotionListener(this);
    public void update(Graphics g) {
    paint(g);
    public void paint(Graphics g) {
    for (int i=0; i < display.length; i++) {
    display[i].setText("i: "+Integer.toString(i));
    Graphics2D offscreenG = ((Graphics2D)moviePanel.getGraphics());
    int w = centerPanel.getWidth();
    int h = centerPanel.getHeight();
    background(w,h);
    offscreenG.drawImage(aFrame,0,0,this);
    public void background(int width, int height) {
    aFrame = createImage(width, height);
    Graphics2D aFrameG = ((Graphics2D) aFrame.getGraphics());
    aFrameG.setColor(Color.cyan);
    aFrameG.fillOval(5,5,width/2,height/2);
    public void mouseDragged(MouseEvent e) {
    if (e.getSource() instanceof JTextArea) {
    JTextArea temp = ((JTextArea)e.getSource());
    int x = e.getX();
    int y = e.getY();
    ((JTextArea)e.getSource()).setLocation(temp.getX() + x, temp.getY() + y);
    repaint(); // Remark me out
    public void mouseMoved(MouseEvent e) {
    repaint(); // Remark me out

    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
    Well, the basic answer is that Swing is different than AWT so you need to learn how to code using Swing. Start by reading the [Swing tutorial|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html] for examples and explanations.
    a) the setLocation doesn't work, because the Layout Manager overrides that value based on the rules of the layout manager. This is a good thing. You should always use layout managers and not set the location manually. The tutorial gives examples of using a layout manager.
    b) don't override the update() method in Swing, that is an old AWT trick
    c) don't override the paint() method of the frame. Custom painting, if required, is done by overriding the paintComponent() method. Again the tutorial gives an example.
    If you are tying to add an image to the background of the frame then there are better ways to do it. Search the forum using "background-image" (without the "-") to find postings on this topic.

  • JTextArea.getSelectedText Problem

    hello
    i need to capture a line from a jtext area with a double-click.
    im using getSelectedText whenever someone double-clicks on some text.
    the problem is that the double-click only selects one word of the line.
    can anyone help me?
    thanks

    Swing releated questions should be posted in the Swing forum.
    Check out my example in this posting:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=605026
    If currently selects the line on a single mouse click but that is easily changed.

  • ActionListener / JTextArea Update Problem

    I have a JFrame that implements ActionListener, and the actionPerformed method looks like so:
    public void actionPerformed(ActionEvent myEvent){
         if ("abc".equals(myEvent.getActionCommand()) {
              //new window is created, etc
         } else if ("def".equals(myEvent.getActionCommand()) {
              //new window is created, etc
         someJTextArea.setText(newText);
         repaint();
    }The problem is, the newText relies on the other windows for its content, but for some unknown reason setText() is called before the new windows are closed, and also before newText has been set. I have a feeling this has something to do with the new windows launching their own threads, but I'm lost on how to wait for those windows to close before setting the text.
    Thanks for any help.

    I don't think that it's an issue of new threads being produced, since Swing GUIs and all actionPerformed code gets called on one thread, the EDT.
    More importantly to me: what exactly are your "new window"s? JFrames? If so, they likely need to be modal JDialogs. This will stop execution of any further method calls in your actionPerformed method until the dialogs have been fully dealt with.

  • JTextArea - Tab problem

    When I'm in the text area when I press Tab key it's inserted into the text area but I want it to go to the next focusable component. Could you help? How do I do it?

    I incorporated a more generic solution of Michaels suggestion with some other examples I have found:
        This is my understanding of how tabbing works. The focus manager
        recognizes the following default KeyStrokes for tabbing:
        forwards:  TAB or Ctrl-TAB
        backwards: Shift-TAB or Ctrl-Shift-TAB
        In the case of JTextArea, TAB and Shift-TAB have been removed from
        the defaults which means the KeyStroke is passed to the text area.
        The TAB KeyStroke inserts a tab into the Document. Shift-TAB seems
        to be ignored.
        This example shows different approaches for tabbing out of a JTextArea
        Also, a text area is typically added to a scroll pane. So when
        tabbing forward the vertical scroll bar would get focus by default.
        Each approach shows how to prevent the scrollbar from getting focus.
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextAreaTab extends JFrame
        public TextAreaTab()
            Container contentPane = getContentPane();
            contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
            contentPane.add( nullTraversalKeys() );
            contentPane.add( writeYourOwnAction() );
            contentPane.add( useKeyListener() );
            contentPane.add( addTraversalKeys() );
        //  Reset the text area to use the default tab keys.
        //  This is probably the best solution.
        private JComponent nullTraversalKeys()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Null Traversal Keys\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            scrollPane.getVerticalScrollBar().setFocusable(false);
            textArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
            textArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
            return scrollPane;
        //  Replace the Tab Actions. A little more complicated but this is the
        //  only solution that will place focus on the component, not the
        //  vertical scroll bar, when tabbing backwards (unless of course you
        //  have manually prevented the scroll bar from getting focus).
        private JComponent writeYourOwnAction()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Write Your Own Tab Actions\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            InputMap im = textArea.getInputMap();
            KeyStroke tab = KeyStroke.getKeyStroke("TAB");
            textArea.getActionMap().put(im.get(tab), new TabAction(true));
            KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB");
            im.put(shiftTab, shiftTab);
            textArea.getActionMap().put(im.get(shiftTab), new TabAction(false));
            return scrollPane;
        //  Use a KeyListener
        private JComponent useKeyListener()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Use Key Listener\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            scrollPane.getVerticalScrollBar().setFocusable(false);
            textArea.addKeyListener(new KeyAdapter()
                public void keyPressed(KeyEvent e)
                    if (e.getKeyCode() == KeyEvent.VK_TAB)
                        e.consume();
                        KeyboardFocusManager.
                            getCurrentKeyboardFocusManager().focusNextComponent();
                    if (e.getKeyCode() == KeyEvent.VK_TAB
                    &&  e.isShiftDown())
                        e.consume();
                        KeyboardFocusManager.
                            getCurrentKeyboardFocusManager().focusPreviousComponent();
            return scrollPane;
        //  Add Tab and Shift-Tab KeyStrokes back as focus traversal keys.
        //  Seems more complicated then just using null, but at least
        //  it shows how to add a KeyStroke as a focus traversal key.
        private JComponent addTraversalKeys()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Add Traversal Keys\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            scrollPane.getVerticalScrollBar().setFocusable(false);
            Set set = new HashSet( textArea.getFocusTraversalKeys(
                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS ) );
            set.add( KeyStroke.getKeyStroke( "TAB" ) );
            textArea.setFocusTraversalKeys(
                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set );
            set = new HashSet( textArea.getFocusTraversalKeys(
                KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS ) );
            set.add( KeyStroke.getKeyStroke( "shift TAB" ) );
            textArea.setFocusTraversalKeys(
                KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set );
            return scrollPane;
        class TabAction extends AbstractAction
            private boolean forward;
            public TabAction(boolean forward)
                this.forward = forward;
            public void actionPerformed(ActionEvent e)
                if (forward)
                    tabForward();
                else
                    tabBackward();
            private void tabForward()
                final KeyboardFocusManager manager =
                    KeyboardFocusManager.getCurrentKeyboardFocusManager();
                manager.focusNextComponent();
                SwingUtilities.invokeLater(new Runnable()
                    public void run()
                        if (manager.getFocusOwner() instanceof JScrollBar)
                            manager.focusNextComponent();
            private void tabBackward()
                final KeyboardFocusManager manager =
                    KeyboardFocusManager.getCurrentKeyboardFocusManager();
                manager.focusPreviousComponent();
                SwingUtilities.invokeLater(new Runnable()
                    public void run()
                        if (manager.getFocusOwner() instanceof JScrollBar)
                            manager.focusPreviousComponent();
        public static void main(String[] args)
            TextAreaTab frame = new TextAreaTab();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    }

Maybe you are looking for

  • Problem to playback 16/9on DVD Player...original export HD to SD 16/9

    Hi, I need some serious help on that one ( need to complete the project for this Friday..) Basically I created an edit on FCP on a timeline with the following settings: -aspect ratio:HDTV 720p (16/9). As it has been shot with a JVC camera(GY-HD111)on

  • Is there a way to restore an accidentally deleted activity log?

    I am soooo embarrassed.  I accidentally deleted the activity log of a phone number I wish to keep.  Is there anyway that I can have that activity restored or is it gone forever?? 

  • File lock in real time job

    Hi All, I encountered an file lock error when creating a real time job. After a dataflow, I have a script to move the processed file to archive folder. (e.g. move c:\source\order.xml c:\archive). When I test run it, I received a 50306 error. It saids

  • Why do my (raw) pictures display differently in LR2 and CS4 ???

    Hello, When I "Open with CS4" from LR2 the pictures seem to be opened as "raw" unprocessed pictures. LR2 did not ask for any options (which it does once I have modified the image in LR2). The raw develop screen from CS4 does not open... any Ideas? cu

  • Cannot open sub-forums

    From the acrobat.com forum I'm trying to do some self-help but every sub-forum I select generates the message "Not authorized to view the specified forum 2182".  I'm an acrobat.com subscriber and according to my browser I'm signed in -what do I need