SetCursor no effect on jtextArea

I would like to change the cursor on a jTextArea that has been set to non-editable. Anyone can show me a way to do that ? Thanks

Do you get the text cursor when it is set to non-editable?? If so just reset it to the default cursor which should be pointer:
jtextarea.setCursor(java.awt.Cursor.getDefaultCursor());

Similar Messages

  • Swing JTextArea

    Hi,
    Ok so previously I used TextArea in my application...
    TextArea ta = new TextArea();
    so normally i would update the textarea...
    ta.append("with some string");
    Now the textarea in java.awt normally has scrollbars
    and would display the most recent text!
    How do I go about achieving the same effect with JTextArea?
    Do I have to use the the JScrollbar?
    Any help much appreciated!

    Hello,
    first sorry for my slightly rude posting but its difficult to guess where problems are without code snippets and sixth sense.
    Try SwingUtilities [url http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html#invokeLater]invokeLater :import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Temp extends JFrame
         Temp()
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              final JTextArea text = new JTextArea();
              final JScrollPane scroll = new JScrollPane(text);
              scroll.setPreferredSize(new Dimension(300,300));
              getContentPane().add(scroll);
              JButton addGarbage = new JButton("add some garbage");
              addGarbage.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        text.append("SomeGarbageSomeGarbageSomeGarbageSomeGarbageSomeGarbageSomeGarbageSomeGarbageSomeGarbage\n");
                        SwingUtilities.invokeLater(new Runnable(){
                             public void run(){
                             JScrollBar horBar = scroll.getHorizontalScrollBar();
                             horBar.setValue(horBar.getMaximum());
              getContentPane().add(addGarbage, BorderLayout.SOUTH);
              pack();
              setLocationRelativeTo(null);
              setVisible(true);
         public static void main(String[] args){new Temp();}
    }I think you had a problem with your horizontal scrollbar because it alway jumps to the left.
    regards,
    Tim

  • How to repaint a JTextArea inside a JScrollPane

    I am trying to show some messages (during a action event generated process) appending some text into a JTextArea that is inside a JScrollPane, the problem appears when the Scroll starts and the text appended remains hidden until the event is completely dispatched.
    The following code doesnt run correctly.
    ((JTextArea)Destino).append('\n' + Mens);
    Destino.revalidate();
    Destino.paint(Destino.getGraphics());
    I tried also:
    Destino.repaint();
    Thanks a lot in advance

    Correct me if I am wrong but I think you are saying that you are calling a method and the scrollpane won't repaint until the method returns.
    If that is so, you need to use threads in order to achieve the effect you are looking for. Check out the Model-View-Contoller pattern also.

  • Problem with JTextArea wanting to resize itself

    First, here is a program that will create the situation in which this error occurs:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class Example extends JFrame
        private final String TITLE       = "Example";
        private final int    WIDTH       = 640;
        private final int    HEIGHT      = 480;
        private JMenuBar     menuBar     = new JMenuBar();
        private JMenu        modeMenu    = new JMenu( "Mode" );
        private JMenuItem    mode1       = new JMenuItem( "Mode 1" );
        private JMenuItem    mode2       = new JMenuItem( "Mode 2" );
        private JTextArea    textArea1   = new JTextArea();
        private JTextArea    textArea2   = new JTextArea();
        private JScrollPane  scrollPane1 = new JScrollPane( textArea1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
        private JScrollPane  scrollPane2 = new JScrollPane( textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
        private JPanel       everything  = new JPanel( new BorderLayout() );
        private JPanel       modeOptions = new JPanel();
        private int          modeInt     = 1;
        public Example ()
            setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            setSize( WIDTH, HEIGHT );
            setLocation( 100, 100 );
            setResizable( true );
            mode1.addActionListener( new ActionListener()
                public void actionPerformed ( ActionEvent e )
                    modeInt = 1;
                    updateModeOptions();
            mode2.addActionListener( new ActionListener()
                public void actionPerformed ( ActionEvent e )
                    modeInt = 2;
                    updateModeOptions();
            modeMenu.add( mode1 );
            modeMenu.add( mode2 );
            menuBar.add( modeMenu );
            setJMenuBar( menuBar );
            updateModeOptions();
            initializeLayout();
        private void updateModeOptions ()
            modeOptions.removeAll();
            switch ( modeInt )
                case 1:
                    JLabel text = new JLabel( "Change to Mode 2 to see the text areas shrink." );
                    modeOptions.add( text );
                    setTitle( TITLE + " - " + "Mode 1" );
                    break;
                case 2:
                    JPanel temp = new JPanel();
                    JLabel text = new JLabel( "Text in a JPanel, to show change in text area size." );
                    temp.add( text );
                    modeOptions.add( temp );
                    setTitle( TITLE + " - " + "Mode 2" );
                    break;
                default:
                    break;
            setVisible( true );
        private void initializeLayout ()
            JPanel panel1 = new JPanel( new BorderLayout() );
            JPanel panel2 = new JPanel( new BorderLayout() );
            JPanel everythingCenterPanel = new JPanel();
            everything.setBorder( BorderFactory.createEtchedBorder() );
            panel1.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Scroll Pane 1" ) );
            panel2.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Scroll Pane 2" ) );
            everythingCenterPanel.setLayout( new BoxLayout( everythingCenterPanel, BoxLayout.Y_AXIS ) );
            panel1.add( scrollPane1 );
            panel2.add( scrollPane2 );
            everythingCenterPanel.add( panel1 );
            everythingCenterPanel.add( modeOptions );
            everythingCenterPanel.add( panel2 );
            everything.add( everythingCenterPanel );
            add( everything );
        public static void main ( String[] args )
            new Example().setVisible( true );
    }Try changing between Mode 1 and Mode 2 (via the Mode menu) to see how the text areas resize as the object between them grows and shrinks. This behavior is correct.
    What is incorrect is what happens when the user enters a large amount of text into one of the text boxes (6 or 7 lines of text should be enough to create the problem) and switches between modes.
    I've tried using the getSize and setSize methods of various components at various points in the program but none seem to work effectively. The closest thing I've been able to do is to keep the JTextAreas, the JScrollPanes, and the JPanels holding them to remain the same sizes, but the text still pushes the panel between the JTextAreas down (and possibly out of) the window, leaving a blank area between the edge of the JPanel containing the JScrollPane and the JPanel in the center.
    The JPanels containing the JScrollPanes must be able to resize correctly as the user resizes the window, so a constant size would not work in this situation.
    Any help is greatly appreciated.

    What is incorrect is what happens when the user enters a large amount of text into one of the text boxes I don't notice anything happening when I add text to the text area. The scrollbars appear as is expected. The only difference for me when I switch between mode 1 and 2 is that the center panel changes in size slightly. This is because the panel is using a FlowLayout which by default has a 5 pixel vertical gap between each component. This is easily fixed by using:
    JPanel temp = new JPanel( new FlowLayout(FlowLayout.CENTER, 5, 0) );I know you tested using JDK1.5 since I had to make the following change in order to get the example to work:
    getContentPane().add( everything );
    So maybe this is a version problem since I don't notice anything out of the ordinary other than what I already mentioned.

  • JTextField and JTextArea don't get focus occuasionally

    I am developing a Java Swing Applet. At edit mode, JComboBox, JCheckBox, JRadioBox, and JButton work fine, but JTextField and JTextArea can't get focus occuasionally while I click them.
    Anyone has idea?
    Thanks

    Thank you Himanshu,
    but that's not exactly what my issue is. This link describes the undesired effect of ending up outisde of the player window and in the browser.
    My problem is kind of the opposite. When I launch the page in the html file I cannot use the tab key to get to any of the controls in the captivate window. I'm stuck in the browser unless I click on the captivate window. That is not acceptable if we want it accessible without using a mouse. I found a way to make it work for chrome like I stated above, but not in FF. Do you have any ideas for this?
    Thanks!
    Monique

  • Uneditable JTextArea

    I have created a simple JTextArea with a scrollPane
    printJTextArea = new JTextArea();         // setting up my text area for output
          printJScrollPane = new JScrollPane(printJTextArea); // putting my text area in a scrollpane
          printJScrollPane.setBounds( 220, 111, 330, 325 ); // setting boundries
          contentPane.add( printJScrollPane ); At the moment though i can type in this text area when my apllication is running. How can i make it uneditable?

    tjacobs01 wrote:
    RTFMthats usually more effective with a link to the FM. : )
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTextArea.html
    though setEditable is inherited from:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/JTextComponent.html

  • Changing Fonts in JTextArea

    Is there a way to have a JTextArea select all the text currently typed inside it and have it change the font size? I've tried <JTextArea>.setFont(new Font("Serif", Font.PLAIN, 16) and that doesn't seem to work. Any ideas? I'm certain it's either a very simple fix or impossible...little middle ground.

    Remove the MouseListeners from the divider so it can't respond to MouseEvents:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    public class SplitPaneFixedDivider extends JFrame
         public SplitPaneFixedDivider()
              JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
              JPanel top = new JPanel();
              top.setPreferredSize( new Dimension(500, 400) );
              top.setBackground( Color.RED );
              splitPane.setTopComponent( top );
              JPanel bottom = new JPanel();
              bottom.setPreferredSize( new Dimension(500, 100) );
              bottom.setBackground( Color.BLUE );
              splitPane.setBottomComponent( bottom );
              getContentPane().add(splitPane);
              BasicSplitPaneUI splitPaneUI = (BasicSplitPaneUI)splitPane.getUI();
              Component divider = splitPaneUI.getDivider();
              divider.setCursor(null);
              MouseListener[] actions = (MouseListener[])divider.getListeners(MouseListener.class);
              for (int i = 0; i < actions.length; i++)
                   divider.removeMouseListener( actions[i] );
              MouseListener[] action3 = (MouseListener[])splitPane.getListeners(MouseListener.class);
              for (int i = 0; i < action3.length; i++)
                   splitPane.removeMouseListener( action3[i] );
              setResizable( false );
         public static void main(String[] args)
              SplitPaneFixedDivider frame = new SplitPaneFixedDivider();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }Of course this defeats the purpose of using a JSplitPane, so an easier solution, as suggested above, is to just use a LayoutManager to mimic the look of a JSplitPane. I prefer the BorderLayout:
              JPanel top = new JPanel();
              top.setPreferredSize( new Dimension(500, 400) );
              top.setBackground( Color.RED );
              getContentPane().add(top, BorderLayout.NORTH );
              JPanel middle = new JPanel();
              middle.setPreferredSize( new Dimension(500, 10) );
              getContentPane().add( middle );
              JPanel bottom = new JPanel();
              bottom.setPreferredSize( new Dimension(500, 100) );
              bottom.setBackground( Color.BLUE );
              getContentPane().add(bottom, BorderLayout.SOUTH );
              setResizable( false );

  • JTextArea is making cells bigger with TableLayout

    I've added a JTextArea onto a JPanel which has TableLayout as its layout manager. I've attached a JScrollPane onto the JTextArea.
    Im trying to make the scroll pane do its job when the text becomes too much for the cells' allocation for the JTextArea. Right now its just making the cells bigger which forces the whole GUI to scroll downwards (or sideways) as opposed to just the JTextArea scrolling and leaving the cell sizes the same.
    Hope im making sense.
    Any ideas?

    Hi,
    sure that the size of the corresponding column and row was set to TableLayout.FILL (you specify this by calling the constructor of TableLayout)? I have got the same effect if I had set the size to TableLayout.PREFERRED ...

  • NewLine with JTextArea and PrintStream

    Hello,
    I'm having a problem with the new line character:
    I'm appending some Strings to a JTextArea using "\n":
    jta.append("save\n");and printing the text of the JTextArea in a txt file:
    FileOutputStream fout;
    try {
         fout = new FileOutputStream("editing.txt");
         PrintStream p = new PrintStream(fout);
         p.println(jta.getText());
         fout.close();
    }If I open the txt file with Notepad it does not start a new line when a "\n" is found (and does not show the "\n" string), but if I open the file with WordPad it works fine.
    Instead, if I print the file using many of these
    fout = new FileOutputStream("editing.txt");
    PrintStream p = new PrintStream(fout);
    p.println(line1);
    p.println(line2);
    p.println(line3);
    ...both Notepad and WordPad read it as I want.
    Does PrintStream.println() use a different character for new lines?
    What should I append to the JTextArea to get the same effect?
    Thank you

    You are better off using -
    System.getProperty("line.separator")
    You might set a value like:
    public static final String EOL = System.getProperty("line.separator");
    //  then use it ...
    String s = "This"+EOL+"That";
    System.out.println(s);
    JTextArea jta = new JTextArea(s);
    // etc ... Edited by: abillconsl on Mar 30, 2010 5:04 PM

  • Resize smaller not working for JTextArea

    I have a series of JTextAreas and JTextFields being added to a JPanel. The problem is I want them to always be the same size as the JPanel in the horizontal direction. This works fine for expanding the window, the JTextAreas and JTextFields expand with the panel to the edge, but then when I try to shrink the window the fields keep their maximum width as their width so when input is given to the field it does not word wrap until it has reached the edge of the maximum width rather than the current width.
    Here's the relevant code:
    JPanel rightSide = new JPanel();
           GridBagLayout gridBag = new GridBagLayout();
           GridBagConstraints constraints = new GridBagConstraints();
           rightSide.setLayout(gridBag);
           constraints.fill = GridBagConstraints.BOTH;
           rightSide.setBackground(BGCOLOR);
           Iterator iter = leafs.iterator();
           constraints.fill = GridBagConstraints.BOTH;
           constraints.weighty = 0.0;
           constraints.weightx = 1.0;
           constraints.gridwidth = GridBagConstraints.REMAINDER;
           while(iter.hasNext()){
             compare = (LeafItem)iter.next();
             textComponent =  compare.getComponent();
             //if the leaf needs a textArea put it in a scrollPane
             if(textComponent.getClass().equals(JScrollPane.class)){
               JLabel label = new JLabel(compare.getDescriptiveName());
               JTextArea textArea = new JTextArea();
               textArea.setLineWrap(true);
               textArea.setWrapStyleWord(true);
               if(HAS_BORDER)
              textArea.setBorder(blackline);
               gridBag.setConstraints(label, constraints);
               gridBag.setConstraints(textArea, constraints);         
               rightSide.add(label);
               rightSide.add(textArea);
             else{
               JLabel label = new JLabel(compare.getDescriptiveName());
               JTextField text = new JTextField();
               gridBag.setConstraints(label, constraints);
               gridBag.setConstraints(text, constraints);
               rightSide.add(label);
               rightSide.add(text);
           rightSide.setBorder
             (BorderFactory.createEmptyBorder(5, 10, 10, 10));
           JPanel remainder = new JPanel();
           remainder.setBackground(BGCOLOR);
           constraints.weighty = 1.0;
           constraints.weightx = 0.0;
           gridBag.setConstraints(remainder, constraints);
           rightSide.add(remainder);
           JScrollPane scrollPane = new JScrollPane
             (rightSide, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
              JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
           splitPane.setRightComponent(scrollPane);
         }

    I'm thinking it may be a bug with JSplitPane.Hm ... maybe our understanding of the JSplitPane is wrong in this context - I try to imagine, if it is normally needed, that components within one of this panes should be resized so that they fit the viewport. If I think about that, I have to say "normally not" - so, I guess, that is not a bug, it should be done in another way.
    Also I do not really understand, in which way you want them to be resized - if you shift the pane separator, the components should not be resized, or do you want them to be resized so that they fit the smaller viewport too?- And if you want them to resize, what if you hide one pane totally?-
    When asking myself this questions, it seems to me, that JSplitPane works correct the way it does it - the effect, you want, must be done in another way and also more specified, I guess.
    greetings Marsian

  • Aligning text in a JTextArea

    Hi,
    I have created a JTextArea object that is 3 rows by 6 columns. I am trying to align the text which is set later. Any suggestions?

    Assigning a Layout Manager to a JTextarea has the same effect as assigning one to a JLabel -> nothing.
    To layout a JTextarea you could use spaces to format the text in it (not very interesting).
    If you want to layout the text use one of the other Text Object, for example JTextPane or JEditorPane.
    Rommie.

  • JTextArea never looses focus

    I have a simple gui that is giving me problems, for some reason when I reset the componments one of my JTextAreas still has focus. If I go and click to write in JTextArea B, theres still another cusor in the A ..... ???? And when I go back to the A, and try to write in A, it appends in the B. Why would the cusor still thinks its in the other JTextArea, Basically now, I have two cusors in my Frame ......... Can any one help me ???
    Thanks

    Heres a sample of my code, cause the whole thing is way too long ....
         JPanel pEdit = new JPanel();
         static Document EDtaProbDoc;
         static Document EDtaInteDoc;
         static JScrollPane EDspProb           = new JScrollPane();
         static JScrollPane EDspInte           = new JScrollPane();
         static JLabel EDlbNoAppel                = new JLabel();
         static JLabel EDlbContact                = new JLabel();
         static JLabel EDlbNoCon                = new JLabel();
         static JLabel EDlbCli                = new JLabel();
         static JLabel EDlbTel                = new JLabel();
         static JLabel EDlbPost                = new JLabel();
         static JLabel EDlbDetEquip                = new JLabel();
         static JLabel EDlbDetProb                = new JLabel();
         static JLabel EDlbDetInte                = new JLabel();
         static JComboBox EDchNoAppel           = new JComboBox();
         static JTextField EDtfContact           = new JTextField();
         static JTextField EDtfTel           = new JTextField();
         static JTextField EDtfPost           = new JTextField();
         static JTextField EDtfAutre           = new JTextField();
         static JTextField EDtfCli                = new JTextField();
         static JTextField EDtfNoCon           = new JTextField();
         static JComboBox EDchDetEquip                = new JComboBox();
         static JTextArea EDtaDetProb                = new JTextArea();
         static JTextArea EDtaDetInte                = new JTextArea();
         static JButton EDbtSau                = new JButton();
    /*********               ADDING TO PANEL ******************/
              pEdit.setLayout(null);
              EDlbNoAppel.setText("Number call");
              EDlbNoAppel.setBounds(new Rectangle(75, 38, 125, 23));
              EDlbContact.setText("Contact");
              EDlbContact.setBounds(new Rectangle(426, 38, 125, 23));
              EDlbNoCon.setText("No Contrat");
              EDlbNoCon.setBounds(new Rectangle(75, 75, 125, 23));
              EDlbCli.setText("Client");
              EDlbCli.setBounds(new Rectangle(75, 57, 125, 23));
              EDlbTel.setText("T�l�phone");
              EDlbTel.setBounds(new Rectangle(426, 58, 125, 23));
              EDlbPost.setText("Post");
              EDlbPost.setBounds(new Rectangle(426, 76, 125, 23));
              EDlbDetEquip.setText("Equipement");
              EDlbDetEquip.setBounds(new Rectangle(75, 110, 125, 23));
              EDlbDetProb.setText("Problem ");
              EDlbDetProb.setBounds(new Rectangle(75, 145, 125, 23));
              EDlbDetInte.setText("Intervention");
              EDlbDetInte.setBounds(new Rectangle(75, 300, 125, 23));
              EDchNoAppel.setBounds(new Rectangle(149, 41, 235, 20));
              EDtfContact.setBounds(new Rectangle(500, 44, 235, 20));
              EDtfNoCon.setBounds(new Rectangle(149, 79, 235, 20));
              EDtfCli.setBounds(new Rectangle(149, 61, 235, 20));
              EDtfTel.setBounds(new Rectangle(500, 62, 235, 20));
              EDtfTel.setToolTipText("Format (###)###-####");
              EDtfPost.setBounds(new Rectangle(500, 80, 235, 20));
              EDchDetEquip.setBounds(new Rectangle(186, 110, 550, 20));
              EDtaDetProb.setBounds(new Rectangle(77, 170, 657, 115));
              EDtaDetProb.setLineWrap(true);
              EDtaDetProb.setWrapStyleWord(true);
              EDspProb.setBounds(new Rectangle(77, 170, 657, 115));
              EDspProb.getViewport().add(EDtaDetProb, null);
              EDtaDetInte.setBounds(new Rectangle(77, 325, 657, 115));
              EDtaDetInte.setLineWrap(true);
              EDtaDetInte.setWrapStyleWord(true);
              EDspInte.setBounds(new Rectangle(77, 325, 657, 115));
              EDspInte.getViewport().add(EDtaDetInte, null);
              EDtaInteDoc = EDtaDetInte.getDocument();
              EDtaProbDoc = EDtaDetProb.getDocument();
              KeyStroke key = KeyStroke.getKeyStroke("ENTER");
              EDtaDetInte.getInputMap().put(key,"none");
              KeyStroke key1 = KeyStroke.getKeyStroke("ENTER");
              EDtaDetProb.getInputMap().put(key1,"none");
              EDbtSau.setText("Sauvegarder");
              EDbtSau.setToolTipText("Mise � jour de cet appel");
              EDbtSau.setBounds(new Rectangle(615, 450, 118, 30));
              EDbtSau.addActionListener(this);
              EDbtSau.setEnabled(false);
              EDtfCli.setEditable(false);
    EDtfNoCon.setEditable(false);
    EDchNoAppel.addItemListener(this);
    EDchDetEquip.addItemListener(this);
              pEdit.add(EDchNoAppel, null);
              pEdit.add(EDtfContact, null);
              pEdit.add(EDtfNoCon, null);
              pEdit.add(EDlbNoCon, null);
              pEdit.add(EDlbContact, null);
              pEdit.add(EDlbNoAppel, null);
              pEdit.add(EDtfCli, null);
              pEdit.add(EDtfPost, null);
              pEdit.add(EDlbPost, null);
              pEdit.add(EDlbTel, null);
              pEdit.add(EDlbCli, null);
              pEdit.add(EDtfTel, null);
              pEdit.add(EDchDetEquip, null);
              pEdit.add(EDlbDetEquip, null);
              pEdit.add(EDlbDetProb, null);
              pEdit.add(EDtaDetProb, null);
              pEdit.add(EDtaDetInte, null);
              pEdit.add(EDbtSau, null);
              pEdit.add(EDlbDetInte, null);
    /***********                ACTIONEVENT          *******************/     
              public void actionPerformed(ActionEvent e)
                   Object obj = e.getSource();
                   if (obj== EDbtSau)
                        setCursor(new Cursor(Cursor.WAIT_CURSOR));
                        if (ASGestAdm.SaveAs() == true)
                             emptyPanel("edit");
                             EDbtSau.setEnabled(false);
                        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
         public void emptyPanel(String str)
                   if (str.trim().equals("edit") )
                        EDtfCli .setText("");
                        EDtfContact.setText("");
                        EDtfNoCon.setText("");
                        EDchNoAppel.setSelectedIndex(0);
                        EDtfTel.setText("");
                        EDtfPost.setText("");
                        EDchDetEquip.removeItemListener(this);
                        EDchDetEquip.removeAllItems();
                        EDchDetEquip.addItemListener(this);
                        EDtaDetProb.setText("");
                        EDtaDetInte.setText("");
              PLUS I'M ONLY HAVING THIS PROBLEM ON THE SECOND RESET, THEN ON THE THIRD TIME THERE ARE CURSORS
              IN BOTH TEXTAREA ....
              THANKS AGAIN

  • Displaying progress with JTextArea

    Hi,
    As newbie, I'm trying to test a concept to see if I can get the new data be appended and displayed immediately in a JTextArea. I wrote a little application that display the number as it loops through in actionPermformed interface. I put a short pause so I can see the number being refreshed into JtextArea. However, what I get is the application process all the loop and repaint the text area with all numbers. As a result, I don't the get progressing paint effect as the application loop through in for loop. What method I should use to achieve this effect? Here is the code I use.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Loop extends JFrame implements ActionListener{
          JTextArea taNum = null;
          JButton btnLoop = null;
          JTextField tfNum = null;
          JScrollPane jspNum= null;
          public Loop (){
            setSize (100,200);
            setLocationRelativeTo(null);
            Container pane = getContentPane();
            pane.setLayout (new GridBagLayout());
            GridBagConstraints c = new GridBagConstraints();
            c.anchor = GridBagConstraints.WEST;
            tfNum = new JTextField(10);
            c.gridx=0;
            c.gridy=0;
            pane.add(tfNum,c);
            btnLoop = new JButton ("Loop");
            btnLoop.addActionListener(this);
            c.gridx=1;
            c.gridy=0;
            pane.add(btnLoop,c);
            taNum = new JTextArea("Start",5,20);
            jspNum = new JScrollPane(taNum);
            c.gridx=0;
            c.gridy=2;
            c.gridwidth=2;
            c.gridheight=2;
            c.ipady=20;
            pane.add(jspNum,c);
            pack();
            setVisible(true);           
          public void actionPerformed (ActionEvent e){
           try{ 
             for (int i =0;i<Integer.parseInt(tfNum.getText());i++){
               taNum.append(Integer.toString(i)+'\n');
               taNum.setCaretPosition(taNum.getDocument().getLength());
               repaint();
               Thread.sleep(500);
            } catch (InterruptedException ex){
              ex.printStackTrace();
          public static void main (String [] argv){
              Loop l = new Loop();
    /*************************************/Thank in advance.
    Kim
    Edited by: kimtitu on Oct 1, 2010 2:03 PM

    1) Read the "Welcome to the new home" posting at the top of the forum for information on the proper way to add code to a posting
    2) Swing related questions should be posted in the Swing forum which is found under "Java Desktop" from the forums home page.
    3) Read the section from the Swing tutorial on [url http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html]Concurrency for more information about why it doesn't work and for one possible solution.

  • JTextArea - LINE_SEPARATOR

    Hi together,
    I want to read an XML file as UTF-8-Text file, and show it in JTextArea. (Without XML validation, on Windows XP)
    My Filereader (see below) uses as line separator System.getProperty("line.separator");
    i.e. on XP this method returns *[\r\n]* So there are 2 characters.
    The content will be displayed in JTextArea. Untill here everything works fine.
    However, when the mouse cursor is at the end of a line,
    if I want to move the mouse "1-step" to the left side, I must click twice.
    A workaround could be to use ony *[\n]* instead *[\r\n]* while reading the file.
    But wenn I use *[\n]* and save the content and open it with XP notepad, all lines of the xml file is on 1 line.
    So notepad requires *[\r\n]* as line separator.
    My problem is:
    - Say, the file is saved with *[\r\n]* as line separator,
    but when I show the content in JTextArea, if the mouse cursor is at the end, I don't want to click [arrow to left] button twice.
    - Generally spoken: How can handle my problem in a different way?
    I hope I could describe my problem.
    Aykut
    Filereader:
        public static String getTextContent(File file, JFrame parentFrame) {
            String content = "";
            try {
                if (!file.isFile()) {
                    return content;
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsoluteFile()), "UTF8"));
                String buf = null;
                int i = 0;
                while ((buf = in.readLine()) != null) {
                    if (i>0) {
                        content += System.getProperty("line.separator");
                    content += buf;
                    i++;
            } catch (IOException e) {
                javax.swing.JOptionPane.showMessageDialog(parentFrame, e.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
            return content;
        }

    sureshot324 wrote:
    Your code manually inserts a line separator wherever the file has it's own line separator, therefore the resulting string has two line separators wherever there should be one. This is probably why you have to move the cursor twice. I'm assuming that the file's own line separators are not recognized properly in the JTextArea and aren't causing it to go to a new line, which is what lead you to do this in the first place. I'm not sure what the best solution is. You probably will need to read it in such a way that replaces the line separators with \n. Maybe camickr's method will do that.No, readLine() chops the line separators off, so he's just replacing the separators from the file with his own. The problem is that JTextArea is designed to use "\n" alone. The default View classes completely ignore the "\r" in "\r\n", so they're invisible and have no effect on the layout. But the Document classes can't ignore them, so you end up with quirky behavior like sometimes having to hit the arrow key twice to move one position. The read() method solve that problem by honoring all three types of separator ("\n", "\r\n" and "\r") but replacing them all with "\n" in the Document.

  • JTextArea wraping but not working on window resize

    Real noob here...
    I'm having a problem when doing a simple listing of folder/file directory within a JTextArea. I would like to simply list each folder or file per line.
    Example:
    Folder1
    Folder2
    File1
    File2
    File3
    With some messy coding, where I add blank space after the folder/file, I can get it to look like above. But when you resize the window, that all goes out the window (no pun inteneded).
    Example after resizing:
    Folder1 Folder2
    File1 File2
    File3
    Notice how now, they are no longer on individual lines.
    I've tried embedding the JTextArea into a JScrollPanel, but has not effect as again, resizing the window still causes the problem.
    What can I do to fix this situation?

    Thanks for the quick reply...
    First let me state that I'm experimenting with Java and Swing... so I have no doubt that I might looking in the wrong place.
    I'm just trying to list the contents (folders and/or files) of a particular directory. Another example might be listing the contents of a file, that may just be names of people.
    I was attempting to output this listing to a JTextArea. How do you list each item on individual lines? I've attempted to do so, but when I resize the window, the items are no longer displayed on one line.
    A real simple concept, but again, there may be other better equipted classes out there...

Maybe you are looking for

  • Create an XML file from Java

    I'm a new user of XML. I've a very important question: Is it possible create an XML file using some java package? If yes what package i must use? JDOM is the right product? Thanks

  • How to select multiple logs in Transaction Code SLG1

    Hi all, I have application log, it is working fine but i need to select multiple logs to download. it has the facility to download one log file at time. but i need to select multiple logs to download. can any one suggest or give some piece of code or

  • Podcasts not work iOS 7

    I downloaded iOS 7 and ever since my podcasts will not sync from my computer to my phone.  Have downloaded the updates and nothing has helped.  I have checked to sync all podcats from my phone, tried changing this to just syncing selected podcasts an

  • Open form in a stacked canvas

    Hello all, I have a content canvas which has a stacked canvas on it. the content canvas i want to use as background and there will be buttons to navigate through different forms and have those forms called on the stacked canvas. Can u please tell me

  • How do i deleat songs from my ipad & iphone

    How do I deleat songs  from my ipad and iphone. They are downloaded from itune. Thanks