JTextArea on a JLabel

Hi,
I extends a JLabel object to display my images. I want to display a JTextArea(on the JLabel) on the mouse position when the user click on the JLabel.
Is it possible to display a JTextArea over a JLabel in absolute position?
Thanks
Patrick

Maybe.. but I need to display the JTextArea over the JLabel...
Can I add the JLabel to a panel and add the JTextArea in the panel but display it over the JLabel?
Maybe I can do it with fixing the JPanel layout to null and you absolute position for both element?
Patrick

Similar Messages

  • Add a JLabel below a JTextArea in a boxlayout

    I have a JTextArea in a JScrollPane in a GUI, and I'm using BoxLayout. Occasionally, I wish to add a JLabel to my JScrollPane, which works fine.
    However, since my BoxLayout is set to the Y_Axis layout, the JLabel always ends up being centered below the JTextArea, and I want it, as well as the JTextArea, to be aligned to the left. I know there is a LEFT_ALIGNMENT operator, but I am unsure of how to use it, although I've read the API for java.awt.Component.
    Also, my JTextArea has a maximum column size, but when the JLabel is displayed, the JTextArea stretches across my entire JScrollPane window. I've tried setting a maximum size, but for some reason that tends to cut off some text on the left side of the JTextArea.
    The JLabel will almost always be wider than the JTextArea. Perhaps that is causing some problems with BoxLayout?
    If there's any more information I should provide, please let me know.
    Thanks for any help you can provide,
    Dan
    Message was edited by:
    Djaunl

    Ok I figured out how the align the JLabel to the left:
    myJLabel.setAlignmentX(Component.LEFT_ALIGNMENT);However, I'm having an odd problem with my JTextArea. If my GUI displays the text normally, everything is fine. But once I add a JLabel to my JScrollPane that is wider than the view (i.e. so I need to scroll horizontally to see the entire JLabel), when I load more text, the text will not position itself within the JScrollPane view, and I will have to scroll over to see all of the text, which I do not want to do.
    Is there a way to keep the JTextArea at the same maximum column number, even though there is a JLabel below it that is much wider than the JTextArea should be?
    I get the feeling this isn't making sense. Here's the code to create my components:
    // Create min/max dimensions
              Dimension minimumSize = new Dimension(200, 500);
              Dimension maximumSize = new Dimension(500, 500);
                    Dimension buttonSize = new Dimension (125, 20);
                    int cols = 30;
              // Create Tree viewing pane
              JScrollPane treeView = new JScrollPane(tree);
              treeView.setMinimumSize(minimumSize);
              treeView.setMaximumSize(maximumSize);
              // Create HTML viewing pane 1
              final JPanel htmlView1 = new JPanel();
                    BoxLayout BL = new BoxLayout(htmlView1, BoxLayout.Y_AXIS);
                    htmlView1.setLayout(BL);
                    final JScrollPane htmlPane = new JScrollPane(htmlView1);
              htmlPane.setMinimumSize(minimumSize);
              htmlPane.setMaximumSize(maximumSize);
                    // Create text area1
                    final JTextArea textArea1 = new JTextArea();
                    textArea1.setLineWrap(true);
                    textArea1.setWrapStyleWord(true);
                    textArea1.setColumns(cols);
                    textArea1.setAlignmentX(Component.LEFT_ALIGNMENT);
                                            JLabel pic = new JLabel (new ImageIcon(new URL(DBQuery.list.get(1))));
                                            pic.setAlignmentX(Component.LEFT_ALIGNMENT);
                                            htmlView1.add(pic);Later in the code, I add textArea1 to htmlView1.
    I'm sorry if this is very confusing. If there is anything I can do to help, please let me know.

  • JTextArea over JLabel(image for background) Can't Receive Mouse Events

    Hi, I use JLabel for putting background image to a JWindow. But when i put a JTextArea component, i can see and edit the contents but JtextArea only receives keyboard events. When i click on it ,its Focus Gained Event is not fired. No blinking cursor is shown.
    I tried to use JLayeredPane and put them on different layers but it doesn't solve the problem.
    I searched the Forums but can't find a suitable answer.
    Any comments please...

    hey man,
    your problem happen not because your JTextArea over a JLabel, but cause JWindow not take focuse before jdk1.4, so if you need to see your blinking cursor just replace your JWindow with a JFrame.
    for the JTExtArea focusing problem, u may refer to the sun bug forum there is a lot of work around.

  • How can I set background for JTextArea

    plz help me!

    textArea.setBackground(Color.black);What's the problem? If you need an image, you could try layering the JTextArea over a JLabel, and have the background of the JTextArea transparent. It might work.

  • JTextArea doesn't loose the focus

    Hi everybody,
    I programmed a graphical interface with two JTextAreas and six JTextFields. Using the program
    means that I delete the text of both JTextAreas and paste new text. An algorithm calculates
    the results. After that I insert new text and start the algorithm again. After two or three deletions
    and insertions one of the JTextAreas doesn't loose the focus and I can't write on it, but I can
    click to another field or area and then I have got two mouse pointer.
    I hope someone has an idea.
    Thank you for your help. Katja

    Please post your code so that somebody may check for
    you.Here the source code of one JTextArea.
    seq1label = new JLabel("Target sequence:");
         sequence1 = new JTextArea("MAEPFSTILGTDGSGGRCKYLNKGIVGLGSYG", 10, 100);
         sequence1.setFont(fontplain);
         sequence1.setBackground(general.BACKCOLOR);
         JScrollPane scrollpane1 = new JScrollPane(sequence1);
         JPanel panelseq1 = general.makePanel();
         panelseq1.setLayout(new BorderLayout());
         panelseq1.add(introduction, BorderLayout.NORTH);
         panelseq1.add(seq1label, BorderLayout.CENTER);
         panelseq1.add(scrollpane1, BorderLayout.SOUTH);
    I hope it is enough.

  • GUI resizes when calling JLabel.setText()

    Case:
    I have a GUI with a GridbagLayout.
    This is the code for building the GUI.
    Important bits:
    please note the scrollConsole and adding it way at the end, because that's getting bigger:
    NOTE: KwartoButtons are a selfmade class that behaves like a button.
         setSize(600,600);
              Container p1 = getContentPane();
              p1.setLayout(new GridBagLayout());
                        GridBagConstraints c = new GridBagConstraints();
                        c.gridx = 0;
                        c.insets.set(5,8,5,8);
                   p1.setBackground(Color.DARK_GRAY);
                          panelVeld = new JPanel(new GridLayout(4,4));
                          panelStukken = new JPanel(new GridLayout(4,4));
                          labelVeld = new JLabel("Speelveld");
                          labelOngespeeld = new JLabel("Ongespeelde Stukken");
                        buttonStop = new JButton("Stop");
                          buttonConsole = new JButton("Hide/Show Console");
                          buttonStart = new JButton("Start");
                   textAreaConsole = new JTextArea("");
                   buttonPanel = new JPanel(new FlowLayout());
                   textAreaConsole.setFont(new Font("Courier",Font.PLAIN, 12));
                   aanZet = new JLabel("Niemand aan zet");
                          labelVeld.setForeground(Color.LIGHT_GRAY);
                          labelOngespeeld.setForeground(Color.LIGHT_GRAY);   
                       aanZet.setForeground(Color.LIGHT_GRAY);
                       scrollConsole = new JScrollPane(textAreaConsole,                   JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                      buttonPanel.add(buttonStart);
                      buttonPanel.add(buttonStop);
                      buttonPanel.setBackground(Color.DARK_GRAY);
                     for(int i=0; i < veld.length; i++)
                          veld[i] = new KwartoButton(null, i, true);
                          veld.addMouseListener(this);
                   veld[i].setEnabled(false);
                   panelVeld.add(veld[i]);
              Set<Stuk> stukkenSet = spel.getOngespeeld();
              int i=0;
              for(Stuk stuk: stukkenSet)
                   stukken[i] = new KwartoButton(stuk, i, false);
                   stukken[i].addMouseListener(this);
                   stukken[i].setEnabled(false);
                   panelStukken.add(stukken[i]);
                   i++;
              c.fill = GridBagConstraints.NONE;     
              c.gridx = 0;
                   p1.add(labelVeld, c);
              c.gridx = 1;
                   p1.add(labelOngespeeld, c);
              c.weightx = 0.5;
              c.weighty = 0.9;
              c.fill = GridBagConstraints.BOTH;     
              c.gridx = 0;
                   p1.add(panelVeld, c);
              c.gridx = 1;
                   p1.add(panelStukken, c);
              c.fill = GridBagConstraints.VERTICAL;
              c.gridx=0;
              c.gridwidth=2;
              c.weightx=0;
              c.weighty=0;
              p1.add(aanZet,c);
              c.fill = GridBagConstraints.VERTICAL;     
              c.weighty = 0.0;               
              c.gridy=3;
              c.gridwidth=1;
              c.gridx=0;
                   p1.add(buttonPanel, c);
              c.gridx=1;
                   p1.add(buttonConsole, c);
              c.gridwidth = GridBagConstraints.REMAINDER;     
              c.gridx=0;
              c.gridy=4;
              c.weightx = 1.0;
    c.weighty = 0.1;     
                   c.fill = GridBagConstraints.BOTH;
              p1.add(scrollConsole, c);          
    This is the code I run when the resize happens:
    public void setMessage(String s)  {
    String message =""
    message =s
                  if(!message.equals("")) {
                       addToConsole(message);
                       aanZet.setText(message);
    public void addToConsole(String s)  {
                   // Determine whether the scrollbar is currently at the very bottom position.
                   JScrollBar vbar = scrollConsole.getVerticalScrollBar();
                   boolean autoScroll = ((vbar.getValue() + vbar.getVisibleAmount()) == vbar.getMaximum());
                   // append to the JTextArea (that's wrapped in a JScrollPane named 'scrollPane'
                   textAreaConsole.append(s+"\n");
                   // now scroll if we were already at the bottom.
                   if( autoScroll ) textAreaConsole.setCaretPosition( textAreaConsole.getDocument().getLength() );
         }What my GUI does: When I invoke setMessage(), my scrollConsole grows about one line, until it overpowers the entire GUI (except the buttons).
    If I remove the 'auto-scrolldown' functionality of addToConsole, it still resizes, so I reckon that's not the problem.

    Here you go.
    Thanks in advance.
    import java.awt.*;
    import javax.swing.*;
    * SSCCE Class for my problem.
    * Problem: GUI Resizes after calling the update method.
    public class TestingClass extends JFrame {
                   private JTextArea textAreaConsole;
                   private JLabel aanZet;
                   private JScrollPane scrollConsole;
         public void update(String s) {          //the problematic method
                       addToConsole(s);                         
                       aanZet.setText(s);
       public void addToConsole(String s) { //adds text to console
                   // Determine whether the scrollbar is currently at the very bottom position.
                   JScrollBar vbar = scrollConsole.getVerticalScrollBar();
                   boolean autoScroll = ((vbar.getValue() + vbar.getVisibleAmount()) == vbar.getMaximum());
                   // append to the JTextArea (that's wrapped in a JScrollPane named 'scrollPane'
                   textAreaConsole.append(s+"\n");
                   // now scroll if we were already at the bottom.
                   if( autoScroll ) textAreaConsole.setCaretPosition( textAreaConsole.getDocument().getLength() );
         public TestingClass() {
              super("Test");
              buildGUI();
              setVisible(true);
              update("a");
              update("b");
              update("c");
                   update("d");
                        update("e");
                             update("f");
                                  update("g");
                                       update("h");
                                            update("i");
                                                 update("j");
                                                      update("k");
                                                           update("l");
                                                                update("m");
                                                                     update("n");
                                                                          update("o"); //add more to see more effect, remove to kill problem
         public void buildGUI() { //building the gui
              setSize(600,600);
              Container p1 = getContentPane();
              p1.setLayout(new GridBagLayout());
                        GridBagConstraints c = new GridBagConstraints();
                        c.gridx = 0;
                        c.insets.set(5,8,5,8);
                        JPanel panelVeld = new JPanel(new GridLayout(4,4));
                JPanel panelStukken = new JPanel(new GridLayout(4,4));
                        textAreaConsole = new JTextArea("");
                        textAreaConsole.setFont(new Font("Courier",Font.PLAIN, 12));
                        aanZet = new JLabel("Test!");
                      scrollConsole = new JScrollPane(textAreaConsole, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                 for(int i=0; i < 16; i++)
                          panelVeld.add(new JButton("x"));
                          panelStukken.add(new JButton("y"));
          c.weightx = 0.5;
          c.weighty = 0.9;
          c.fill = GridBagConstraints.BOTH;     
          c.gridx = 0;
                p1.add(panelVeld, c);
          c.gridx = 1;
                   p1.add(panelStukken, c);
                 c.fill = GridBagConstraints.VERTICAL;
                 c.gridx=0;
                 c.gridwidth=2;
                 c.weightx=0;
                 c.weighty=0;
                      p1.add(aanZet,c);
                 c.gridwidth = GridBagConstraints.REMAINDER;     
                 c.gridx=0;
                 c.gridy=4;
                 c.weightx = 1.0;
          c.weighty = 0.1;                    
                   c.fill = GridBagConstraints.BOTH;            
                      p1.add(scrollConsole, c);
    public static void main(String[] args) { //starting up!
              new TestingClass();
    }

  • JLabel Editing

    For the past few days I have been struggling with creating a GUI for a program I am developing with the aim of extracting index.dat files. The user selects the file they wish to analyse, the program outputs various details to the interface. However, I am having issues trying to implement this with the JLabel 'size'. Others such as the JTextAreas have not yet been attempted.
    The program itself runs fine in the background however, none of the details are added to the interface itself.
    The following is the code I have so far for implementing the GUI, apologise if this seems messy, however I have been editing it quite abit recently trying to solve the issue. Not all aspects of this program have been implemented yet, such as methods for editing the JTextAreas, as I am currently just trying to solve the setIndexInfo() method when editing the 'size' JLabel.
    public class GUInterface extends JFrame implements ActionListener
        //creating GUI variables
        JMenuBar menuBar;
        JMenu file;
        JMenuItem historyItem, flashItem, exit;
        JFileChooser filechoose;
        JPanel info, top, output, cacheDisplay;
        JTextArea cache, display;
        JLabel type, loc, size;
        JScrollPane scrollpane;
        File f = new File("C:\\");
        String locStr;
        public void create()
            guInterface();
        }//end create
        public void guInterface()
            //initialising variables
            menuBar = new JMenuBar();
            file = new JMenu("File");
            historyItem = new JMenuItem("Index.dat");
            flashItem = new JMenuItem("Flash Cookies");
            exit = new JMenuItem("Exit");
            filechoose = new JFileChooser();
            info = new JPanel();
            top = new JPanel();
            cacheDisplay = new JPanel();
            cache = new JTextArea(9, 10);
            type = new JLabel("AnalysisType");
            loc = new JLabel("FileLoc");
            size = new JLabel("Size");
            //creating menu bar
            menuBar.add(file);
            file.add(historyItem);
            file.add(flashItem);
            file.addSeparator();
            file.add(exit);
            //info
            info.setLayout(new BoxLayout(info, BoxLayout.Y_AXIS));
            type.setFont(new Font("Serif", Font.BOLD, 30));
            info.add(type);
            info.add(Box.createRigidArea(new Dimension(0,5)));
            loc.setFont(new Font("Serif", Font.BOLD, 20));
            info.add(loc);
            info.add(Box.createRigidArea(new Dimension(0,5)));
            size.setFont(new Font("Serif", Font.BOLD, 20));
            info.add(size);
            //cacheDisplay
            cacheDisplay.add(cache);
            cache.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
            cache.setMaximumSize(new Dimension(200, 200));
            cache.setLineWrap(true);
            cache.setEditable(false);
            cache.setSize(200,100);
            //top panel
            top.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
            top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS));
            top.add(info);
            top.add(Box.createHorizontalGlue());
            top.add(cache);
            filechoose.setCurrentDirectory(f);
            historyItem.addActionListener(this);
            flashItem.addActionListener(this);
            exit.addActionListener(this);
            setJMenuBar(menuBar);
            //JFrame layout
            setLayout(new BorderLayout());
            add(top, BorderLayout.NORTH);
            //creating main area
            setSize(1000, 600);
            setLocationRelativeTo(null);
            setTitle("PrivateBrowse - Private Browsing Recovery Tool");
            setResizable(false);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        }//end guInterface
        public void setIndexInfo(String output)
            size = new JLabel(output);
            size.setFont(new Font("Serif", Font.BOLD, 20));
        }//end setIndexInfo
        public void actionPerformed(ActionEvent evt)
            if(evt.getSource() == historyItem)
                 filechoose.setDialogTitle("Select index.dat");
                 filechoose.setFileSelectionMode(JFileChooser.FILES_ONLY);
                 if(filechoose.showOpenDialog(null) == filechoose.APPROVE_OPTION)
                     type.setText("Index.DAT Analysis");
                     locStr = filechoose.getSelectedFile().toString();
                     loc.setText(locStr);
                     try
                       IndexRecovery idxRcvy = new IndexRecovery();
                       idxRcvy.readFile(locStr);
                     catch(Exception e)
                         System.out.println("Error: " + e);
            else if(evt.getSource() == flashItem)
                filechoose.setDialogTitle("Select #SharedObjects Directory");
                filechoose.setApproveButtonText("Select");
                filechoose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                if(filechoose.showOpenDialog(null) == filechoose.APPROVE_OPTION)
                    type.setText("Flash Cookie Analysis");
                    locStr = filechoose.getSelectedFile().toString();
                    loc.setText(locStr);
                    try
                        FlashRecovery flshRcvy = new FlashRecovery();
                        flshRcvy.extractFlash(locStr);
                    catch(Exception e)
                        System.out.println("Error: " + e);
            else if(evt.getSource() == exit)
                setVisible(false);
                dispose();
                System.exit(0);
        }//end actionPerformed
    }The class IndexRecovery calls setIndexInfo() with the size wanted to be displayed in the JLable 'size'.
    I have been looking around and heard of various functions such as repaint() and validate(), however have no clue how to use these should these be the solution.
    Any advice on the matter will be greatly appreciated.
    Thanks,
    David.

        public void setIndexInfo(String output)
            size.setText(output);
        }//end setIndexInfoOr this, to be thread safe:
    public void setIndexInfo(final String output) {
        if (SwingUtilities.isEventDispatchThread()) {
            size.setText(output);
        } else {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    setIndexInfo(output);
    }//end setIndexInfoEdited by: Andre_Uhres on Apr 6, 2010 4:58 PM

  • How can I see   more than one text line?

    Can anyone help me??
    I know to write more than one line in a HstaticText with the following code
    label = new HStaticText("This is some text.  It's a fairly long " +
                                    "\npiece of text that should show \nword wrapping on most " +
                                    "receivers.\nMultiple lines of text are\n supported " +
                                    "by the text layout\n manager if them are\n separated " +
                                    "by a \\n", 0,0, 600, 600, new Font("Tiresias", Font.BOLD, 30), Color.blue, colors[0], new HDefaultTextLayoutManager());but when I have tried the following code and I can�t.
    private String texto="Pulse cualquier bot�n. \n para averiguar su Keycode";
    g.drawString(texto,x_pos,y_pos);     // Graphics gPlease help me!

    Graphics.drawString() doesn't format the text into lines based on embedded linefeeds. You have to split the text into lines yourself and use multiple drawStrng() calls, giving it the correct starting location each time. This "HstaticString" class is obviously doing that for you behind the scenes. If you want to draw multiline text without using an HstaticString, I suggest using either a JTextArea, or a JLabel with HTML text:  JLabel lbl = new JLabel("<html>Pulse cualquier bot�n.<br><br>para averiguar su Keycode</html>");

  • How can i replace some string  in a JTextaArea/JTex at current time!

    Hey guys, this problem is driving me crazy... i want to do a keyboard event.. like the emoticons in msn,
    so, i want that when i type /land ("latex comand"), a character appears replacing the command in the JTextArea. I did it, but when i type
    /happy, the character doesn�t appear! Just when i type space in keyboard...:/
    Can anybody help me?
    public class TelaParametro extends JDialog {
         private GerenciadorExterno gerInterface;
         private TelaLeis telaLeis;
         private int parametro;
         private Argument argumento;
         private String codigo;
         private String path = "images/";
         private TecladoVirtual tecl;
         private boolean DigitandoLatex;
         private String latex;
         /* atributo que serve para dizer se o usuario apertou no Ok ou no Cancel */
         private int flagModal;
           JPanel panel1 = new JPanel();
           JButton btnOK = new JButton();
           JButton btnCancel = new JButton();
           JTextArea tfEspec = new JTextArea();
           JScrollPane rolagem;
           JLabel labelEntrada = new JLabel();
           JButton btnDigitacao = new JButton();
           JButton btnTecladoVirtual = new JButton();
         JPanel panel2 = new JPanel();
         BorderLayout borderLayout1 = new BorderLayout();
         BorderLayout borderLayout2 = new BorderLayout();
         JPanel panel3 = new JPanel();
         GridLayout gridLayout1 = new GridLayout();
         JPanel panel4 = new JPanel();
         BorderLayout borderLayout3 = new BorderLayout();
         JPanel panel5 = new JPanel();
         JPanel panel6 = new JPanel();
         JPanel panel7 = new JPanel();
         JPanel panel8 = new JPanel();
    public TelaParametro(TelaLeis telaLeis, GerenciadorExterno gerInterface) {
              super(telaLeis);
              try  {
                   this.telaLeis = telaLeis;
                   this.gerInterface = gerInterface;
                   this.tecl = new TecladoVirtual(this);
                   flagModal = 0;
                   DigitandoLatex = false;
                   jbInit();
              catch (Exception e) {
                     e.printStackTrace();
    private void jbInit() throws Exception {
                 this.setLocation(240,220);
    //             this.setLocation((gerInterface.getTamanhoHorizontal()/2) - 160,(gerInterface.getTamanhoVertical()/2) - 80);
                 this.setSize(320, 160);
                 this.setTitle("Parametro");
                 tfEspec.setFont(new Font ("CZT", Font.PLAIN, 12));
                 tfEspec.setText("");
              rolagem = new JScrollPane(tfEspec);
              this.setModal( true );
              tfEspec.addKeyListener(new java.awt.event.KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        tfEspec_keyPressed(e);
              btnOK.setForeground(Color.green);
              btnOK.setFont(new Font("Dialog", 1, 12));
              btnOK.setLabel(this.retornarMensagem("COD0072"));
              btnOK.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        btnOK_actionPerformed(e);
              btnDigitacao.setFont(new Font("Dialog", 1, 12));
              btnDigitacao.setText("D");
              btnDigitacao.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(ActionEvent e) {
                   btnTecladoVirtual_actionPerformed(e);
              ImageIcon teclicon = new ImageIcon(path + "teclado.gif");
              btnTecladoVirtual.setIcon(teclicon);
              btnTecladoVirtual.setToolTipText("TecladoVirtual");
              btnTecladoVirtual.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(ActionEvent e) {
                   btnTecladoVirtual_actionPerformed(e);
              btnCancel.setForeground(Color.red);
              btnCancel.setFont(new Font("Dialog", 1, 12));
              btnCancel.setLabel(this.retornarMensagem("COD0078"));
              btnCancel.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(ActionEvent e) {
                        btnCancel_actionPerformed(e);
              labelEntrada.setText("   Entre com tal parametro:");
              panel1.setLayout(borderLayout1);
              panel2.setLayout(borderLayout2);
              panel3.setLayout(gridLayout1);
              panel4.setLayout(borderLayout3);
              this.getContentPane().add(panel1, BorderLayout.CENTER);
              panel1.add(panel2, BorderLayout.CENTER);
              panel2.add(rolagem,  BorderLayout.CENTER);
              panel2.add(panel5, BorderLayout.WEST);
              panel2.add(panel6,  BorderLayout.SOUTH);
              panel2.add(panel7,  BorderLayout.EAST);
              panel2.add(panel8, BorderLayout.NORTH);
              panel1.add(panel3,  BorderLayout.SOUTH);
              panel3.add(btnOK, null);
              panel3.add(btnCancel, null);
              panel1.add(panel4, BorderLayout.NORTH);
              panel4.add(labelEntrada,  BorderLayout.CENTER);
              panel4.add(btnTecladoVirtual,  BorderLayout.EAST);
    private void tfEspec_keyPressed(KeyEvent e){
             String str = tfEspec.getText() ;
             System.out.println("char "  + e.getKeyChar());
             System.out.println("texto " + str);
             str = str.replace("\\land", ZString.AND);
             //System.out.println("strReplaced " + str);
             tfEspec.setText(str);
             tfEspec.repaint();
    }

    But there is no method "addDocumentListener" for JTextArea =/ [url http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html]How to Write a Document Listener.

  • 1.4.2 Java Swing problems

    I have a swing application with 2 JComboBox 's, 1 JPanel (for pictures), 1 JButton and a scroll pane. Basicall the JComboBoxes have an action listener that changes the pictures when I cahnge the names. However, I would like the Jbutton when pressed to display the name chosen (from the JComboBox) and display it in the textArea. See code below.
    import javax.swing.*;
    import javax.swing.Action;
    import java.awt.event.ActionEvent;
    import  java.awt.event.ItemListener;
    import java.awt.*;
    import java.awt.event.*;
    * @author Administrator
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class choice_in2 extends JPanel implements ActionListener{
         private JLabel contender1FieldLabel;
         private JLabel contender2FieldLabel;
         private JButton runButton;
         JLabel picture1;
         JLabel picture2;
         //Text area which shows the result
         private JTextArea textArea;
         private JLabel textAreaLabel;
         public choice_in2(){
              //          Create a ChoiceField for the input of first contender
              contender1FieldLabel = new JLabel("Contender1 ",4);
              String[] contender1Strings = { "Bill", "Bob", "Don", "Michael", "John" };
              JComboBox contender1List = new JComboBox(contender1Strings);
              contender1List.setSelectedIndex(1);
              contender1List.addActionListener(new Eavesdropper1(picture1));
              //          Create a ChoiceField for the input of second contender
              contender2FieldLabel = new JLabel("Contender2 ",4);
              String[] contender2Strings = { "Philip", "Timothy", "Tom", "Kenneth", "Stone" };
              JComboBox contender2List = new JComboBox(contender2Strings);
              contender2List.setSelectedIndex(2);
              contender2List.addActionListener(new Eavesdropper2(picture2));
            //Set up the first picture.
            picture1 = new JLabel();
            picture1.setFont(picture1.getFont().deriveFont(Font.ITALIC));
            picture1.setHorizontalAlignment(JLabel.CENTER);
            updateLabel1(contender1Strings[contender1List.getSelectedIndex()]);
            picture1.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
            //Set up the second picture.
            picture2 = new JLabel();
            picture2.setFont(picture1.getFont().deriveFont(Font.ITALIC));
            picture2.setHorizontalAlignment(JLabel.CENTER);
            updateLabel2(contender2Strings[contender2List.getSelectedIndex()]);
            picture2.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
            //The preferred size is hard-coded to be the width of the
            //widest image and the height of the tallest image + the border.
            //A real program would compute this.
            picture1.setPreferredSize(new Dimension(200, 220+10));
            picture2.setPreferredSize(new Dimension(200, 220+10));
              // Create a JButton that will compute
              runButton = new JButton("Compute");
              runButton.addActionListener(new Eavesdropper3(textArea));
              // Create a JTextArea that will display the results
              textAreaLabel = new JLabel("Results");       
              textArea = new JTextArea(10,70);
              textArea.setFont(new Font("Courier",Font.PLAIN,12));
              JScrollPane scrollPane =  new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
              textArea.setEditable(false);
            //Lay out the demo.
            add(contender1List, BorderLayout.WEST);
            add(picture1, BorderLayout.WEST);
            add(contender2List, BorderLayout.EAST);       
            add(picture2, BorderLayout.EAST);
            add(runButton, BorderLayout.EAST);
            add(textAreaLabel, BorderLayout.SOUTH);
            add(scrollPane, BorderLayout.SOUTH);
            setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
        /** Listens to the combo box. */
        public void actionPerformed(ActionEvent e) {
        public void updateLabel1(String name1) {
            ImageIcon icon1 = createImageIcon( name1 + ".jpg");
            picture1.setIcon(icon1);
            picture1.setToolTipText("A drawing of a " + name1.toLowerCase());
            if (icon1 != null) {
                picture1.setText(null);
            } else {
                picture1.setText("Image not found");
        public void updateLabel2(String name2) {
             ImageIcon icon2 = createImageIcon( name2 + ".jpg");
            picture2.setIcon(icon2);
            picture2.setToolTipText("A drawing of a " + name2.toLowerCase());
            if (icon2 != null) {
               picture2.setText(null);
            } else {
                picture2.setText("Image not found");
        /** Returns an ImageIcon, or null if the path was invalid. */
        public ImageIcon createImageIcon(String path) {
            java.net.URL imgURL = choice_in2.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
        class Eavesdropper2 implements ActionListener {
            JLabel myTextArea;
            public Eavesdropper2(JLabel ta) {
                 myTextArea = ta;
            public void actionPerformed(ActionEvent e) {
                JComboBox contender2List = (JComboBox)e.getSource();
                String contender2ListName = (String)contender2List.getSelectedItem();
                updateLabel2(contender2ListName);
                Eavesdropper3 code;
                code = new Eavesdropper3(contender2ListName);
        class Eavesdropper1 implements ActionListener {
            JLabel myTextArea;
            public Eavesdropper1(JLabel tt) {
                 myTextArea = tt;
            public void actionPerformed(ActionEvent e) {
                JComboBox contender1List = (JComboBox)e.getSource();
                String contender1ListName = (String)contender1List.getSelectedItem();
                updateLabel1(contender1ListName);
        class Eavesdropper3  implements ActionListener  {
             String contender22;
            JTextArea myTextArea;
            public Eavesdropper3(JTextArea bb) {
                 myTextArea = bb;
            public Eavesdropper3(String contender2ListName){
                 contender22 = contender2ListName;
               * @return Returns the contender22.
              public String getContender22() {
                   return contender22;
            public void actionPerformed(ActionEvent e) {
                 textArea.setText("Wild Test");
                 textArea.append("\n      OUTCOME    \n\n " +getContender22());
    }

    weebib
    We are using Windows XP , Nvidia graphics card, with Multiview. I hope the problem is not specific to the platform.
    It is reproducible with 1.4.2 and absent in 1.4.1
    camickr
    I am new to this forum. didn't know about code blocks.

  • Scroll bar with flowlayout still does not work

    Why does the scrollbar with my textArea not work?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JEmail extends JFrame implements ActionListener
         JPanel panel = new JPanel(new FlowLayout());
         private final static String newline = "\n";
         JButton button = new JButton("Send");
         JLabel to = new JLabel("TO:");
         JLabel from = new JLabel("From:");
         JTextField tobox = new JTextField(8);
         JTextField frombox = new JTextField(8);
         //     JTextArea email = new JTextArea(5,10);
              JLabel message = new JLabel("Message:");
         //     JScrollPane scroll = new JScrollPane(email);
              JTextArea textArea = new JTextArea(5,10);
              JScrollPane scroll = new JScrollPane(textArea);     
         //JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
         //     JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
         public JEmail()
              super("Email");
              panel.setLayout(new FlowLayout());
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              panel.add(to);
              panel.add(tobox);
              panel.add(from);
              panel.add(frombox);
              panel.add(message);
              panel.add(textArea);
         panel.add(scroll);
              panel.add(button);
              button.addActionListener(this);
         //     email.addAdjustmentListener(this);
              setContentPane(panel);
         public void actionPerformed(ActionEvent e)
              Object source = e.getSource();
              if (source == button)
              textArea.append(newline + "Mail has been sent\n");
              tobox.setText("");
              frombox.setText("");
         public void adjustmentValueChanged(AdjustmentEvent e)
              Object source = e.getSource();
         public static void main(String[] args)
              JFrame aFrame = new JEmail();
              aFrame.setSize(400, 400);
              aFrame.setVisible(true);
    }

    Post the code again, this time using the [ code ] tags.

  • Compare two string in different line in textarea

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
                        public TextCounterPanel() {
                        setBackground(Color.DARK_GRAY);
                        textInput = new JTextArea();
                        textInput.setBackground(Color.WHITE);
                        JPanel south = new JPanel();
                        south.setBackground(Color.DARK_GRAY);
                        south.setLayout( new GridLayout(4,1,2,2) );
                             JButton countButton = new JButton("Process the Text");
                             countButton.addActionListener( new ActionListener() {
                                  public void actionPerformed(ActionEvent evt) {
                                       processInput();
                             south.add(countButton);
                        lineCountLabel = new JLabel(" Number of lines:");
                        lineCountLabel.setBackground(Color.WHITE);
                        lineCountLabel.setForeground(Color.BLUE);
                        lineCountLabel.setOpaque(true);
                        south.add(lineCountLabel);
                        setLayout( new BorderLayout(2,2) );
                        setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
                        JScrollPane scroller = new JScrollPane( textInput );
                        add(scroller, BorderLayout.CENTER);
                        add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel
    How can I compare two string in different line in text area

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
    public TextCounterPanel() {
    setBackground(Color.DARK_GRAY);
    textInput = new JTextArea();
    textInput.setBackground(Color.WHITE);
    JPanel south = new JPanel();
    south.setBackground(Color.DARK_GRAY);
    south.setLayout( new GridLayout(4,1,2,2) );
    JButton countButton = new JButton("Process the Text");
    countButton.addActionListener( new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    processInput();
    south.add(countButton);
    lineCountLabel = new JLabel(" Number of lines:");
    lineCountLabel.setBackground(Color.WHITE);
    lineCountLabel.setForeground(Color.BLUE);
    lineCountLabel.setOpaque(true);
    south.add(lineCountLabel);
    setLayout( new BorderLayout(2,2) );
    setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    JScrollPane scroller = new JScrollPane( textInput );
    add(scroller, BorderLayout.CENTER);
    add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel

  • Input only working once with JTextField

    Hi,
    I've created an GUI with one JTextField, a JTextArea and a JLabel that I use to display an imageIcon. I want the user to be able to input text into the JTextField without having to click on it with the mouse. I've used requestFocus() to do this and it works the first time. I then clear the JTextField using setText(""), so the user can enter more input. After I do this the cursor is still flashing but when I type nothing comes up in the JTextField. I've tried calling requestFocus() after setText() as well but it didn't work either. Does anyone have any ideas?
    Thanks in advance
    JFrame frame = new JFrame("SubjectGUI");
    JPanel pane = new JPanel();
    ImageIcon icon;
    JLabel diagram;
    JTextArea task;
    JTextField textField;
    boolean done = false;
    public SubjectGUI(){
         diagram = new JLabel(icon, JLabel.CENTER);
         icon = new ImageIcon("images/blank.JPEG");
         textField = new JTextField(10);
         task = new JTextArea(new String(""));
         textField.addActionListener(this);
    pane.setLayout(new BorderLayout());
         pane.add(diagram, BorderLayout.NORTH);
         pane.add(task, BorderLayout.CENTER);
         pane.add(textField, BorderLayout.SOUTH);
         task.setEditable(false);
         frame.getContentPane().add(pane);
         frame.pack();
         frame.setVisible(true);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public void setTextField(String text){
         textField.setText( setTexttext);
    public void setGraph(String filePath){
         ImageIcon icon = new ImageIcon(filePath);
         diagram.setIcon(icon);
    public void setTask(String taskString){
         task.setText(taskString);
    public void focus(){
         textField.requestFocus();
    public static void main(String args[]){
         SubjectGUI sgui = new SubjectGUI();
         long start = System.currentTimeMillis();
         sgui.focus();
         for(int i=0;i<3;i++){
         if(i==0){
              sgui.setTextField("");
              sgui.setTask("2+2");
              sgui.setGraph("./images/graph1.JPEG");
         if(i==1){
              sgui.setTextField("");
              sgui.setTask("4+4");
              sgui.setGraph("./images/graph2.JPEG");
         // sgui.focus();
         while((System.currentTimeMillis()<start + 10000) && !(sgui.done())){

    Sorry,
    Here is the entire code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SubjectGUI implements ActionListener{
    JFrame frame = new JFrame("SubjectGUI");
    JPanel pane = new JPanel();
    ImageIcon icon;
    JLabel diagram;
    JTextArea task;
    JTextField textField;
    boolean done = false;
    public SubjectGUI(){
         diagram = new JLabel(icon, JLabel.CENTER);
         icon = new ImageIcon("images/blank.JPEG");
         textField = new JTextField(10);
         task = new JTextArea(new String(""));
         //textField.setActionCommand(this);
         textField.addActionListener(this);
    pane.setLayout(new BorderLayout());
         pane.add(diagram, BorderLayout.NORTH);
         pane.add(task, BorderLayout.CENTER);
         pane.add(textField, BorderLayout.SOUTH);
         task.setEditable(false);
         textField.setMinimumSize(new Dimension(200,400));
         task.setMinimumSize(new Dimension(200,400));
         diagram.setMinimumSize(new Dimension(200,400));
         pane.setPreferredSize(new Dimension(200,400));
         frame.getContentPane().add(pane);
         frame.pack();
         frame.setVisible(true);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public void setTextField(String text){
         textField.setText(text);
    public void setGraph(String filePath){
         ImageIcon icon = new ImageIcon(filePath);
         diagram.setIcon(icon);
    public void setTask(String taskString){
         task.setText(taskString);
    public void focus(){
         textField.requestFocus();
    public void close(){
         frame.dispose();
    public void actionPerformed(ActionEvent evt){
    String text = textField.getText();
         System.out.println(text);
         done=true;
    public static void main(String args[]){
         SubjectGUI sgui = new SubjectGUI();
         long start = System.currentTimeMillis();
         sgui.focus();
         for(int i=0;i<3;i++){
         if(i==0){
              sgui.setTextField("");
              sgui.setTask("2+2");
              sgui.setGraph("./images/graph1.JPEG");
         if(i==1){
              sgui.setTextField("");
              sgui.setTask("4+4");
              sgui.setGraph("./images/graph2.JPEG");
         //sgui.focus();//see previous focus() outside loop
         while((System.currentTimeMillis()<start + 10000) && !(sgui.done)){

  • JTabbedPane with JScrollPane

    The application uses a JTabbedPane, each Tab contains a JScrollPane, the TopComponent contains the same Class with different Classes for the BottomComponent. Each BottomComponent is a separate class and relates to a different table. How can I interface with with the other classes without knowing which Tab is active?

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Property_Features extends JPanel implements ActionListener{
         private JTextArea txtFeature;
         private JLabel image;
         private JButton btnNew = null;
         private JButton btnUpd = null;
         private JButton btnDel = null;
         private JToolTip toolTip = null;
         private Prop_Header propHdr = null;
         private JPanel fPanel = null;
         private JPanel wPanel = null;
         private Box vertBox;     
         private Box topBox;     
         private Box midBox;     
         private Box botBox;     
    public Property_Features(){
         toolTip = new JToolTip();
         vertBox = Box.createVerticalBox();
         topBox = Box.createHorizontalBox();
         midBox = Box.createHorizontalBox();
         botBox = Box.createHorizontalBox();
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         txtFeature = new JTextArea(5,50);
         txtFeature.setFont(new Font("SansSerif", Font.PLAIN, 14));
         txtFeature.setLineWrap(true);
         txtFeature.setWrapStyleWord(true);
         txtFeature.setEditable(true);
         txtFeature.setBorder(BorderFactory.createTitledBorder(" Describe the Property Features"));
         toolTip.setComponent(txtFeature);
         txtFeature.setToolTipText("Enter Property Feature of Major Interest");
         wPanel.add(txtFeature);
         topBox.add(wPanel);
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         btnNew = new JButton(" Add ");
         btnNew.addActionListener(this);
         toolTip.setComponent(btnNew);
         btnNew.setToolTipText("Add Property Feature Information");
         btnUpd = new JButton("Update");
         btnUpd.addActionListener(this);
         toolTip.setComponent(btnUpd);
         btnUpd.setToolTipText("Update Property Feature Information");
         btnDel = new JButton("Delete");
         btnDel.addActionListener(this);
         toolTip.setComponent(btnDel);
         btnDel.setToolTipText("Delete Property Information");
         wPanel.add(btnNew);
         wPanel.add(btnUpd);
         wPanel.add(btnDel);
         midBox.add(wPanel);
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         image = new JLabel("", new      ImageIcon("c:/ATC_Application/images/skiing.jpg"), JLabel.CENTER);
         wPanel.add(image);
         botBox.add(image);
         vertBox.add(topBox);
         vertBox.add(midBox);
         vertBox.add(botBox);
         JSplitPane split = new JSplitPane();
         split.setOrientation(JSplitPane.VERTICAL_SPLIT);
         Prop_Header propHdr = new Prop_Header();
         split.setTopComponent(propHdr);
         split.setBottomComponent(vertBox);
         JScrollPane scrollPane = new JScrollPane(vertBox,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
         scrollPane.setPreferredSize(new Dimension(650,400));
         split.add(scrollPane);
         add(split);
    } // end of Property_Features constructor
    // ActionListener Interface
         public void actionPerformed(ActionEvent e){
              System.out.println("Action Listener " + e.getActionCommand());
    } // end of class
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Prop_Header extends JPanel implements ActionListener{
    private JComboBox cmbProp;
    private JTextField txtPropCode;
    private JTextField txtPropAddr1;
    private JTextField txtPropAddr2;
    private JTextField txtPropCity;
    private JTextField txtPropState;
    private JButton sel;
    private JLabel lblBlk;
    private JPanel pWork;
    private Box vertBox;     
    private Box topBox;     
    private Box midBox;     
    private Box botBox;     
    JToolTip toolTip = null;
    public Prop_Header(){
         vertBox = Box.createVerticalBox();
         topBox = Box.createHorizontalBox();
         midBox = Box.createHorizontalBox();
         botBox = Box.createHorizontalBox();
         cmbProp = new JComboBox();
         cmbProp.addItem(" ");
         cmbProp.setEditable(false);
         cmbProp.setBackground(Color.white);
         cmbProp.setPreferredSize(new Dimension(250,27));
         cmbProp.setFont(new Font("Times-Roman",Font.PLAIN,12));
         cmbProp.addActionListener(this);
         txtPropCode = new JTextField(5);
         txtPropCode.setFont(new Font("Times-Roman",Font.PLAIN,12));
         txtPropCode.setPreferredSize(new Dimension(5,27));
         txtPropCode.addActionListener(this);
         lblBlk = new JLabel(" ");
         sel = new JButton("Select");
         sel.addActionListener( this);
         toolTip = new JToolTip();
         toolTip.setComponent(cmbProp);
         cmbProp.setToolTipText("Select Property Name & Press
    Select button ");
         toolTip.setComponent(txtPropCode);
         txtPropCode.setToolTipText("Enter Property Code & Press
    Select Button ");
         toolTip.setComponent(sel);
         sel.setToolTipText("Display Property Information Based on
    Name or Code Entered ");
         pWork = new JPanel();
         pWork.setLayout(new FlowLayout(FlowLayout.CENTER));
         pWork.setBorder(BorderFactory.createTitledBorder(" Select
    Property Name or Enter Code "));
         pWork.add(new JLabel("Name: "));
         pWork.add(cmbProp);
         pWork.add(new JLabel(" Code: "));
         pWork.add(txtPropCode);
         pWork.add(lblBlk);
         pWork.add(sel);
         topBox.add(pWork);
         txtPropAddr1 = new JTextField("Address line 1",15);
         txtPropAddr1.setEditable(false);
         txtPropAddr2 = new JTextField("Address line 2",15);
         txtPropAddr2.setEditable(false);
         txtPropCity = new JTextField("City",15);
         txtPropCity.setEditable(false);
         txtPropState = new JTextField("State",3);
         txtPropState.setEditable(false);
         toolTip.setComponent(txtPropAddr1);
         txtPropAddr1.setToolTipText("First Address Line of Property");
         toolTip.setComponent(txtPropAddr2);
         txtPropAddr2.setToolTipText("Second Address Line of Property");
         toolTip.setComponent(txtPropCity);
         txtPropCity.setToolTipText("City Name of Property location");
         toolTip.setComponent(txtPropState);
         txtPropState.setToolTipText("State Code of Property location");
         midBox.add(midBox.createVerticalStrut(10));
         botBox.add(new JLabel("Address:"));
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropAddr1);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropAddr2);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropCity);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropState);
         vertBox.add(topBox);
         vertBox.add(midBox);
         vertBox.add(botBox);
         add(vertBox);
    } // end of constructor
         public void actionPerformed(ActionEvent evt){
         } // end of actionPerformed
    } // end of Prop_Header

  • Scrolling log window guff

    Hi,
    I've got an app that executes external processes, monitors the output of each, and puts it in a log window. The problem is, when I append to the contents of the JTextArea, I don't know how to set its preferred size correctly so that the JScrollPane knows how large the TextArea is. I tried using (textArea.getLineCount() * line height), but that doesn't work because word wrap creates more lines than getLineCount() reports -- instead of setting the JTextArea to the proper size, it's always too big or too small (depending on how many lines were wrapped). Here's my code:
    //check and update all the log windows.
    for(int i=0; i < logWindowUpdater.size(); i++)
         javax.swing.JFrame window = (javax.swing.JFrame)(logWindowUpdater.get(i));
         javax.swing.JScrollPane scroll = (javax.swing.JScrollPane)window.getContentPane().getComponent(0);
         javax.swing.JLabel bgImage = (javax.swing.JLabel)window.getContentPane().getComponent(1);
         javax.swing.JTextArea textArea = (javax.swing.JTextArea)scroll.getViewport().getView();
         java.lang.Process process = (java.lang.Process)buildProcessesVector.get(i);
         try
              String processOutput = new java.lang.String();
              while(process.getInputStream().available() > 0)
                   char readByte = (char)process.getInputStream().read();
                   processOutput += readByte;
              textArea.append(processOutput);
              //because of word wrap, this doesn't work correctly!
              textArea.setPreferredSize(new java.awt.Dimension(560, textArea.getLineCount()*25));
              scroll.getVerticalScrollBar.setValue(scroll.getVerticalScrollBar.getMaximum());
         catch(java.lang.Exception e)
              e.printStackTrace();
    Surely there's a way to do this. It's just a simple, autoscrolling log window. Does anyone have suggestions?
    Thanks,
    Jake

    The problem is that I can't properly set the size (or number of rows and columns) of the JTextArea. You see, it is dynamically updated with the output from a running process, which has some unknown number of lines. I can't set the size or rows/columns without knowing how many "lines" are in the process output, and I can't figure that out because word wrap creates some number of additional rows.
    Here's how I create the log window and add the JTextArea:
    private void createLogWindow(String title, java.lang.Process process)
         javax.swing.JFrame logWindow = new javax.swing.JFrame();
         logWindow.setSize(600, 400);
         javax.swing.JScrollPane logScroller = new javax.swing.JScrollPane();
         javax.swing.JTextArea textArea = new javax.swing.JTextArea();
         javax.swing.JLabel bgImage = new javax.swing.JLabel();
         logWindow.setTitle(title);
         textArea.setFont(new java.awt.Font("Monospaced", 0, 12));
         textArea.setLineWrap(true);
         textArea.setOpaque(false);
         textArea.setPreferredSize(new java.awt.Dimension(560, 300));
         logScroller.setViewportView(textArea);
         logScroller.setPreferredSize(new java.awt.Dimension(560,300));
         logWindow.getContentPane().add(logScroller);
         logWindow.setVisible(true);
         //add this log window to the vectors so it can be tracked and updated
         logWindowupdater.add(logWindow);
         buildProcessVector.add(process);
    }Does that make more sense?
    Jake

Maybe you are looking for

  • SQL query, Decode function or Case

    Hi, I am writing a procedure, receiving IN parameter p_user_type_cd where p_user_type possibles values are = 'STUDENT','STAFF','PROVIDER' if p_user_type_cd = 'STUDENT' , I would like to select WHERE user_type_cd = 'STUDENT' if p_user_type_cd = 'ALL'

  • Itunes has encontered an error and needs to close

    Windows xp pro. install itunes fine but everytime i come to running it. it comes up with that error its runing sp2, no firewall's are turned on. Any help please i would be very gr8 full. if i could get hold of a copy of itunes 5 i might try that

  • Horizontal Bar when equal or under 1024x768 in 4:3

    Hi everybody, I have used a width of 1012px for my header, container and footer. I can't think  of another element that might be affecting the total width of the page. The problem is that when I view the page in 4:3 monitors that use 1024x768 resolut

  • Can't import vertical photos, they appear black

    Hi, I'm using Iphoto 9.2.1 with lion 10.7.2. I can't import any vertical photos on iphoto. Instead, I have a black icon and all the files weight 329 ko. They appear perfectly normal on my desktop, and if I rotate to have them horizontal on my desktop

  • 3d PLOT DIRECTION

    How can i programically change the 3D graph direction that I want to view. I know how to view and adjust the projection, but what about the graph's direction meaning XY, XZ, YZ, and user defined... Thanks!