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

Similar Messages

  • Adding JButton to JTextAreas

    I'm publishing reports from data onto an uneditable JTextArea (so the user can save it as a text doc if they wish).
    I'd like to have a button next to each report so the user can view the data for that report, but presumably this can't be done on a JTextArea?
    Anyone have any suggestions as to how I can have a 'View data' button, but still be able to save the text of the report?
    Many thanks.

    If you are trying to produce a panel that has a JTextArea and a JButton on it, that is relatively easy to do.
    You cannot put a JButton into a text area but it is easy enough to put it either next to or below the text area and provide the functionality that you are looking for.

  • Putting long strings on a JLabel

    I want to write a string on a particular rectangular region (e.g. JLabel) and the length of string is more than the width of the rectangle, so it wont fit in one line.
    Is there any API that will automatically calculate where to put the line break and display it accordingly in multiple lines.
    In other words, I want Java equivalent of VC++ function
    Status DrawString(
    const WCHAR *string,
    INT length,
    const Font *font,
    const RectF &layoutRect,
    const StringFormat *stringFormat,
    const Brush *brush
    );

    Other than using an uneditable JTextArea (as suggested above), not APIs exist to do it automagicly.
    You would have to use things like getStringBounds , adding one word at at time, until you go over the length you want, then roll back a work, add a new line, and do it all again.

  • Need help writing custom Swing JComponent

    Hi, I am trying to write my own version of a "comboBox" that does not have a drop-down box, and doesn't have a down-arrow icon on it. What I would really like to do is basically write a class that is a JLabel, but will accept KeyEvents and FocusEvents. Here is an example of exactly what I want, but it is written using an uneditable JTextArea(Hit the up and down arrow Keys to scroll through the options):
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.text.JTextComponent;
    import java.awt.event.KeyListener;
    import java.awt.event.FocusListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.FocusEvent;
    import java.awt.Color;
    import java.awt.Font;
    public class Test implements KeyListener, FocusListener
         Color colorBackgroundFocus = new java.awt.Color(240, 240, 240);
         Color colorText = new Color(0, 0, 128);
         Font fontText = new java.awt.Font("SansSerif", 1, 12);
         JTextArea jTextAreaPOPayment;
         public static void main(String[] args)
              new Test();
         * The Constructor for Test
         public Test(){
              JFrame jFrame = new JFrame("�:o)");
              jFrame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        ((JFrame)e.getComponent()).setVisible(false);
                        ((JFrame)e.getComponent()).dispose();
                        System.exit(0);
              jTextAreaPOPayment = new JTextArea();
              setUnEditableTextProperties(jTextAreaPOPayment, "jTextAreaPOPayment", "Cash", 60, 15, 10, 10);
              jFrame.getContentPane().add(jTextAreaPOPayment);
              jFrame.pack();
              jFrame.setVisible(true);
         * The Following is used to set all the properties for the JTextArea
         public void setUnEditableTextProperties(JTextComponent jTextComponent, String stringVariableName, String stringText, int intSizeX, int intSizeY,
         int intLocationX, int intLocationY){
              jTextComponent.setSize(new java.awt.Dimension(intSizeX, intSizeY));
              jTextComponent.setLocation(new java.awt.Point(intLocationX, intLocationY));
              jTextComponent.setName(stringVariableName);
              jTextComponent.setVisible(true);
              jTextComponent.setForeground(colorText);
              jTextComponent.setBackground(null);
              jTextComponent.setFont(fontText);
              jTextComponent.addFocusListener(this);
              jTextComponent.addKeyListener(this);
              jTextComponent.setEditable(false);
              jTextComponent.setText(stringText);
         * The Following is used to Cycle the Payment Types
         public void cyclePOPayment(boolean booleanUp){
              if (jTextAreaPOPayment.getText().compareTo("Cash") == 0)
                   jTextAreaPOPayment.setText(booleanUp ? "Check" : "Credit");
              else if (jTextAreaPOPayment.getText().compareTo("Credit") == 0)
                   jTextAreaPOPayment.setText(booleanUp ? "Cash" : "Check");
              else if (jTextAreaPOPayment.getText().compareTo("Check") == 0)
                   jTextAreaPOPayment.setText(booleanUp ? "Credit" : "Cash");
         * The Following are needed to implement KeyListener Class
        public void keyTyped(KeyEvent e) {
        public void keyPressed(KeyEvent e) {
              if (e.getComponent().getName().compareTo("jTextAreaPOPayment") == 0)
                   if (e.getKeyText(e.getKeyCode()).equalsIgnoreCase("Up")){
                        cyclePOPayment(true);
                   else if (e.getKeyText(e.getKeyCode()).equalsIgnoreCase("Down")){
                        cyclePOPayment(false);
        public void keyReleased(KeyEvent e) {
         * The Following is needed to implement FocusListener Class
         public void focusGained(FocusEvent e) {
              if (e.getComponent().getName().compareTo("jTextAreaPOPayment") == 0){
                   jTextAreaPOPayment.setBackground(colorBackgroundFocus);
                   jTextAreaPOPayment.select(-1, 0);
        public void focusLost(FocusEvent e) {
              if (e.getComponent().getName().compareTo("jTextAreaPOPayment") == 0){
                   jTextAreaPOPayment.setBackground(null);
    }Here is what I tried to do, but I think I need to write the "fireFocusEvent" method?? I read something about tha tsomewhere, but can't find it again. I tried just implementing the focusListener and KeyListener, and that didn't work...Can someone Help me please!!
    what I tried:
    import javax.swing.JComponent;
    import java.awt.event.FocusListener;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.FocusEvent;
    import java.awt.Graphics;
    import java.awt.Dimension;
    class ComboJLabel extends JComponent implements FocusListener, KeyListener
         String stringText;
         // The preferred size of the gauge
         int Height = 20;  
         int Width  = 20;
         public ComboJLabel(){
              this.stringText = "Test";
         public ComboJLabel(String stringText){
              this.stringText = stringText;
              this.addKeyListener(this);
              this.addFocusListener(this);
         public void keyPressed(KeyEvent e){
              System.out.println("KeyPressed");
         public void keyTyped(KeyEvent e){
              System.out.println("KeyTyped");
         public void keyReleased(KeyEvent e){
              System.out.println("KeyReleased");
         public void focusGained(FocusEvent e){
              System.out.println("Focus Gained");
         public void focusLost(FocusEvent e){
              System.out.println("Focus lost");
         public void setText(String stringNewText){
              stringText = stringNewText;
         public void paint(Graphics g){
           g.setColor(java.awt.Color.black);
           g.drawString(stringText, 3, 15);
         public Dimension getPreferredSize() {
              return new Dimension(Width, Height);
         public Dimension getMinimumSize() {
              return new Dimension(Width, Height);
    import javax.swing.JFrame;
    class TestComboJLabel
         public static void main(String[] args)
              JFrame jFrame = new JFrame();
              ComboJLabel comboJLabel = new ComboJLabel();
              jFrame.getContentPane().add(comboJLabel);
              jFrame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        ((JFrame)e.getComponent()).setVisible(false);
                        ((JFrame)e.getComponent()).dispose();
                        System.exit(0);
              jFrame.pack();
              jFrame.setVisible(true);
    }But that didn't work! If anyone can help, or show me a good site that tells me how to, It would greatly appreciated! Thanks in advanced,
    Jeff �:o)

    Yeah,sorry about the length...If you just grab the first piece of code(that works BTW0, you will see Exactly what I am trying to do...I just don't want to use anything that already exists and Jerry-Rig it...I want to try and create a new JComponent, more as a learning experience than anything else.
    But thanks for the response!

  • Chat Client - JTextPane

    I am trying to build a chat client, within an Applet, communicating with a Java server. I have written the server code, and built all communications (prototyped as a command line tool first, and its all working).
    My only problem now is getting the messages displayed correctly in the chat client.
    I have two problems I am trying to solve
    1) I want the username in a different color to the message
    2) I want the message to wrap, if it goes over a single line
    I have been at this for most of the day, trying different techniques, but the text either does not display at all, or I can only get one of the two problems solved, and not both together.
    I have tried lost of tips already, from previous posts, but not sure if I am doing something wrong, or if it is the applet causing the problem.
    All help would be greatly appreciated.
    Thanks
    Wayne

    My only problem now is getting the messages displayed correctly in the chat client.Start simple. Are you able to display both the user name and the chat text in the client, regardless of color and wrapping?
    I have two problems I am trying to solve
    1) I want the username in a different color to the messageIs using HTML an option? Most (all?) Swing components support text with HTML markup for e.g., colors, style,...
    2) I want the message to wrap, if it goes over a single lineMost (all?) JTextComponent subclasses support line wrapping. Well, OK, not JTextField descendants.
    I have been at this for most of the day, trying different techniques, but the text either does not display at all, or I can only get one of the two problems solved, and not both together.
    I have tried lost of tips already, from previous posts,Which tips? What did you try? What didn't work?
    I'm not nit-picking, but there are several ways we could suggest (e.g. JEditorPane), but why spend time describing them if you already have tried them... Have you read [how to use Editor Pane|http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html] (non-editable version) from the Java tutorial?
    Note than a simpler solution could be to display the user name in a JLabel with some color, and the chat text in a JTextPane or in an uneditable JTExtArea, with line-wrapping enabled, in another color. Not sure if that fulfills your requirements in terms of display.
    but not sure if I am doing something wrong, or if it is the applet causing the problem.Probably not "the applet". But for the sake of simplicity, have you tried running the chat client as a standalone Java app?

  • Modified JFileChooser

    I've browsed through the API and noticed that there are some methods to modify the default JFileChooser (like adding components and such). However, I'm not sure how specific these changes can be and how much control I would have over their placement in the JFileChooser. From what I can gather, I wouldn't have much control.
    First question - How much control would I have over customizing the layout using the JFileChooser methods?
    So my alternative is to design my own file chooser modeled after the JFileChooser. But I'm not sure where to begin on this or what might be involved in designing such an interface and the methods to back it up with functionality.
    Second question - What is a good spot to start learning about designing a UI and implementing the back-end to an emulator for a JFileChooser?

    Part of my application involves uploading files to a networked server from a desktop. I've got nearly all of the "business code" done, but I need a UI to get some information from the user (the files to be copied/uploaded and basic information about the file set) and pass it to my "business" objects.
    Because a JFileChooser has the ability to both gather the files and have an "accessory", I figure that using one would be a great place to start. I would use the JFileChooser for gathering the files and create an accessory that has multiple JPanels each containing components for entering data about the file set being uploaded. The accessory would also be where I would return any error messages by adding new components. If possible, I also want my JFileChooser to "stick around" and have the entry and file selection components become uneditable/unselectable/unusable and activate another part of the accessory - an uneditable JTextArea that displays status messages generated by the validation and upload code to allow the user to observe the actions of the program.
    I only need one view, but I need it to have a lot of components going on, aside from the JFileChooser. It's going to be my entire file copy/upload UI. If it has to do with displaying messages from the upload or validation, it's going to happen inside of the file chooser by adding/removing/hiding/changing components.

  • Can I center the text in vertical direction in JTextArea

    for example , if the JTextArea is 50 pixels high, and the text 's height is 20 pixels,
    then how can I center the text in vertical direction in this JTextArea which means
    there is a extra space whose height is 15 pixels over and under the text?

    Exactly what are you trying to do?
    JTextAreas are usually in a scroll pane, you add multiple lines ie height can change
    are you going to make it uneditable etc
    if it is just for a display (uneditable), perhaps a 'tall' JTextField might give you the desired effect

  • Auto scrolling JTextAreas

    Hi,
    I am having an infuriating problem with my JTextArea which hopefully someone can help me with.
    On my GUI I have a JTextArea in a JScrollPane which is uneditable as it
    is there purely to give the user feedback. The user presses a button
    and the program happily does its thing creating datafiles and other
    such things and all the while telling the user what it is up to.
    The code I use to update the display is this:
    public void updateText(String str)
        textarea.append(string + "\n");
        textarea.paintImmediately();
        textarea.scrollRectToVisible(textarea.modelToView(
                          textarea.getDocument().getLength());
    }This works fine until the text reaches the bottom of the JTextArea
    because what ever the last line of text is, it gets repeated evertime
    it scrolls until the program stops updating the display at which point
    the text changes to what it should be. So for example, if the last text
    was "This is rubbish" before it starts scrolling then the
    display would look like this...
    This is rubbish
    This is rubbish
    This is rubbish
    This is rubbish....(and so on until the end where it changes to the proper text).
    One thing I have noticed is that the last line in the JTextArea before
    scrolling starts has about the bottom two rows of pixels missing from
    the text, could this be causing the scrolling to mess up. I have tried
    making the JTextArea double buffered and swapping the order of the
    scrolling and the paintImmediatly.
    I am really stuck and have searched through the forums trying all the
    usual suggestions for scrolling such as setting the caret position but
    this seems to be the only one that make the JTextArea scroll, albeit
    with a messed up display.
    Please can someone help me, this is really bugging me. (No pun intended).
    Cheers Jim.

    Check this code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    class Test extends JFrame implements ActionListener
         static int nCount = 0;
         JTextArea m_areaTest = null;
         JButton m_btnTest = new JButton("Add");
         public Test()
              m_areaTest = new JTextArea(10,30);
              JScrollPane scrollTest = new JScrollPane(m_areaTest);
              m_areaTest.setLineWrap(true);
              getContentPane().setLayout(new FlowLayout());
              getContentPane().add(scrollTest);
              getContentPane().add(m_btnTest);
              m_btnTest.addActionListener(this);
              addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)
                        dispose();
                        System.exit(0);
         public static void main(String args[])
              System.out.println("Starting CopyPaste...");
              Test mainFrame = new Test();
              mainFrame.setSize(400, 400);
              mainFrame.setTitle("CopyPaste");
              mainFrame.setVisible(true);
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == m_btnTest)
                   m_areaTest.append("This is rubbish"+ nCount+ "\n");
                   nCount++;
                   //m_areaTest.paintImmediately();   
                   //bm_areaTest.scrollRectToVisible(m_areaTest.modelToView(textarea.getDocument().getLength()));
    }regards
    Praveen

  • How to moniter and Replace every character typed into a JTextArea!

    I have a JTextArea!
    For every character typed on it in want to change that character to my own character...
    For example if user types 'a' on key board, i want 'b' to be displayed on the JTextArea.
    It should been seen on the screen...
    Any idea?
    P.N: I am doing a notepad like editor where in user can type Indic languages in phonetic notation... [Yea, Transliteration....] Does any one have any coding for that, Especially for Tamil... I want to get அம்மா, if i type "amma". I have the table of what should be replace with what! but i don't know how to make it work? any idea?

    if user types 'a' on key board, i want 'b' to be displayed on the JTextArea.Add a KeyListener and override the keyTyped method to increment the keyChar field of the KeyEvent.
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.SwingUtilities;
    public class KeyShifter {
      public static void main(String[] args) {
       SwingUtilities.invokeLater(new Runnable() {
         public void run() {
           new KeyShifter().makeUI();
      void makeUI() {
        JTextArea textArea = new JTextArea();
        textArea.addKeyListener(new KeyAdapter() {
          public void keyTyped(KeyEvent ke) {
            char c = (char) (ke.getKeyChar() + 1);
            ke.setKeyChar(c);
        JFrame frame = new JFrame("Key Shifter");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.add(textArea);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    So maybe it'd be better to have two text fields... one what was typed (as per normal) and a JTextArea to display the transliterated text. Just an idea.And a very good idea, Keith... just testing this was creepy! Yup, this could be recoded to append a character other than the one typed, to a second, uneditable, text area. I'd use a Map or some other data structure to get the transliterated character from the one typed.
    db

  • JTextArea on JWindow

    Why can't I make a JTextArea on JWindow uneditable?
    Heres the code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Note extends JWindow {
    JTextArea ta;
    public static void main(String args[]) {
    new Note();
    public Note() {
    ta = new JTextArea("j;lsa ;lasjfasdf asdf sadfsadfsad ;lkasdf ;lksa;lkfs;al fj;lksadfl; l;kslkfdf l");
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);
    ta.setFont(new Font("Verdana",Font.BOLD,24));
    ta.setEditable(true);
    JScrollPane scrollPane = new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(scrollPane,BorderLayout.CENTER);
    setSize(300, 300);
    setVisible(true);
    // Give focus for keystrokes
    requestFocus();
    but when I changed extends JWindow into extends JFrame, ta.setEditable(true) worked fine.
    Please explain it to me. Thank you very much.

    >
    JWindow and focus: If you happen to use a JWindow in your GUI, you should know that the JWindow's owning frame must be visible for any components in the window to get the focus. By default, if you don't specify an owning frame for a JWindow, an invisible owning frame is created for it. The result is that components in JWindows might not be able to get the focus. The solution is to either specify a visible owning frame when creating the JWindow, or to use an undecorated JFrame instead of JWindow.
    from:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html

  • To refresh the contents in JTextArea on selection of a row in JTable.

    This is the block of code that i have tried :
    import java.awt.GridBagConstraints;
    import java.awt.SystemColor;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    import ui.layouts.ComponentsBox;
    import ui.layouts.GridPanel;
    import ui.layouts.LayoutConstants;
    import util.ui.UIUtil;
    public class ElectronicJournal extends GridPanel {
         private boolean DEBUG = false;
         private boolean ALLOW_COLUMN_SELECTION = false;
    private boolean ALLOW_ROW_SELECTION = true;
         private GridPanel jGPanel = new GridPanel();
         private GridPanel jGPanel1 = new GridPanel();
         private GridPanel jGPanel2 = new GridPanel();
         DefaultTableModel model;
         private JLabel jLblTillNo = UIUtil.getHeaderLabel("TillNo :");
         private JLabel jLblTillNoData = UIUtil.getBodyLabel("TILL123");
         private JLabel jLblData = UIUtil.getBodyLabel("Detailed View");
         private JTextArea textArea = new JTextArea();
         private JScrollPane spTimeEntryView = new JScrollPane();
         private JScrollPane pan = new JScrollPane();
         String html= " Item Description: Price Change \n Old Price: 40.00 \n New Price: 50.00 \n Authorized By:USER1123 \n";
         private JButton jBtnExporttoExcel = UIUtil.getButton(85,
                   "Export to Excel - F2", "");
         final String[] colHeads = { "Task No", "Data", "User ID", "Date Time",
                   "Description" };
         final Object[][] data = {
                   { "1", "50.00", "USER123", "12/10/2006 05:30", "Price Change" },
                   { "2", "100.00", "USER234", "15/10/2006 03:30", "Price Change12345"},
         final String[] colHeads1 = {"Detailed View" };
         final Object[][] data1 = {
                   { "Task:Price Change", "\n"," Old Price:50.00"," \n ","New Price:100.00"," \n" }
         JTable jtblTimeEntry = new JTable(data, colHeads);
         JTable jTbl1 = new JTable(data1,colHeads1);
         ComponentsBox jpBoxButton = new ComponentsBox(LayoutConstants.X_AXIS);
         public ElectronicJournal() {
              super();
              jtblTimeEntry.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              if (ALLOW_ROW_SELECTION) { // true by default
    ListSelectionModel rowSM = jtblTimeEntry.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    //Ignore extra messages.
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    System.out.println("No rows are selected.");
    } else {
    int selectedRow = lsm.getMinSelectionIndex();
    System.out.println("Row " + selectedRow
    + " is now selected.");
    textArea.append("asd \n 123 \n");
    } else {
         jtblTimeEntry.setRowSelectionAllowed(false);
              if (DEBUG) {
                   jtblTimeEntry.addMouseListener(new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
         printDebugData(jtblTimeEntry);
              initialize();
         private void printDebugData(JTable table) {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
         private void initialize() {
              this.setSize(680, 200);
              this.setBackground(java.awt.SystemColor.control);
              jBtnExporttoExcel.setBackground(SystemColor.control);
              ComponentsBox cmpRibbonHORZ = new ComponentsBox(LayoutConstants.X_AXIS);
              cmpRibbonHORZ.addComponent(jBtnExporttoExcel, false);
              jpBoxButton.add(cmpRibbonHORZ);
              this.addFilledComponent(jGPanel, 1, 1, 1, 1, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel1, 2, 1, 11, 5, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel2, 2, 13, 17, 5, GridBagConstraints.BOTH);
              jGPanel.setSize(650, 91);
              jGPanel.setBackground(SystemColor.control);
              jGPanel.addFilledComponent(jLblTillNo,1,1,GridBagConstraints.WEST);
              jGPanel.addFilledComponent(jLblTillNoData,1,10,GridBagConstraints.BOTH);
              jGPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0));
              jGPanel1.setBackground(SystemColor.control);
              jGPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              spTimeEntryView.setViewportView(jtblTimeEntry);
              jGPanel1.addFilledComponent(spTimeEntryView, 1, 1, 11, 4,
                        GridBagConstraints.BOTH);
              jGPanel2.addFilledComponent(jLblData,1,1,GridBagConstraints.WEST);
              jGPanel2.setBackground(SystemColor.control);
              jGPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              //textArea.setText(html);
              pan.setViewportView(textArea);
         int selectedRow = jTbl1.getSelectedRow();
              System.out.println("selectedRow ::" +selectedRow);
              int colCount = jTbl1.getColumnCount();
              System.out.println("colCount ::" +colCount);
              StringBuffer buf = new StringBuffer();
              System.out.println("Out Of For");
              /*for(int count =0;count<colCount;count++)
              {System.out.println("Inside For");
              buf.append(jTbl1.getValueAt(selectedRow,count));
              // method 1 : Constructs a new text area with the specified text. 
              textArea  =new JTextArea(buf.toString());
              //method 2 :To Append the given string to the text area's current text.   
             textArea.append(buf.toString());
              jGPanel2.addFilledComponent(pan,2,1,5,5,GridBagConstraints.BOTH);
              this.addAnchoredComponent(jpBoxButton, 7, 5, 11, 5,
                        GridBagConstraints.CENTER);
    This code displays the same data on the JTextArea everytime i select each row,but my requirement is ,it has to refresh and display different datas in the JTextArea accordingly,as i select each row.Please help.Its urgent.
    Message was edited by: Samyuktha
    Samyuktha

    Please help.Its urgentThen why didn't you use the formatting tags to make it easier for use to read the code?
    Because of the above I didn't take a close look at your code, but i would suggest you should be using a ListSelectionListener to be notified when a row is selected, then you just populate the text area.

  • How to Capture New Line in JTextArea?

    I apologize if this is easy, but I've been searching here and the web for a few hours with no results.
    I have a JTextArea on a form. I want to save the text to a database, including any newline characters - /n or /r/n - that were entered.
    If I just do a .getText for the component, I can do a System.println and see the carriage return. However, when I store and then retrieve from the database, I get the lines concatenated.
    How to I search for the newline character and then - for lack of a better idea - replace it with a \n or something similar?
    TIA!

    PerfectReign wrote:
    Okay, nevermind. I got it.
    I don't "see" the \n but it is there.
    I added a replaceAll function to the string to replace \n with
    and that saves to the database correctly.
    String tmpNotes = txtNotes.getText().replaceAll("\n", "<br />");Oh, you're viewing the text as HTML? That would have been good to know. ;)
    I'll have to find a Wintendo machine to try this as well.Be careful not to get a machine that that says "Nii!"

  • How to refresh a JPanel/JTextArea

    My main problem is that I don't know how to correctly refresh a JTextArea in an Applet. I have an Applet with 2 internal frames. Each frame is comprised of a JPanel.
    The first internal frame calls the second one as shown below:
    // Set an internal frame for Confirmation and import the Confirm class into it//
    Container CF = nextFrame.getContentPane();
    //<Jpanel>
    confirmation = new Confirmation( );
    CF.add ( confirmation, BorderLayout.CENTER );
    mFrameRef.jDesktopPane1.add(nextFrame,JLayeredPane.MODAL_LAYER);
    currentFrame.setVisible(false); // Hide this Frame
    nextFrame.setVisible(true); // Show Next Frame/Screen of Program
    confirmation (Jpanel) has a JTextArea in it. When it's called the first time it displays the correct information (based on choices from the first frame). If a user presses the back button (to return to first frame) and changes something, it doesn't refresh in the JTextArea when they call the confirmation(Jpanel) again. I used System.out.println (called right after jtextareas code), and it shows the info has indeed changed...I guess I don't know how to correctly refresh a JTextArea in an Applet. Here is the relevent code for the 2nd Internal Frame (confirmation jpanel):
    // Gather Info to display to user for confirmation //
    final JTextArea log = new JTextArea(10,35);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    log.append("Name: " storeInfoRef.getFirstName() " "
    +storeInfoRef.getLastName() );
    log.append("\nTest Project: " +storeInfoRef.getTestProject() );
    JScrollPane logScrollPane = new JScrollPane(log);

    Here is the relevant code that I am having the problem with...
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class Confirmation extends JPanel {
    // Variables declaration
    private StoreInfo storeInfoRef; // Reference to StoreInfo
    private MFrame mFrameRef; // Reference to MFrame
    private Progress_Monitor pmd; // Ref. to Progress Monitor
    private JLabel ConfirmMessage; // Header Message
    private JButton PrevButton;                // Navigation Button btwn frames
    private JInternalFrame prevFrame, currentFrame; // Ref.to Frames
    // End of variables declaration
    public Confirmation(MFrame mFrame, StoreInfo storeInfo) {
    mFrameRef = mFrame; // Reference to MFrame
    storeInfoRef = storeInfo; // Reference to Store Info
    prevFrame = mFrameRef.FileChooserFrame; // Ref. to Previous Frame
    currentFrame = mFrameRef.ConfirmationFrame; // Ref. to this Frame
    initComponents();
    // GUI for this class //
    private void initComponents() {
    ConfirmMessage = new JLabel();
    PrevButton = new JButton();
    UploadButton = new JButton();
    setLayout(new GridBagLayout());
    GridBagConstraints gridBagConstraints1;
    ConfirmMessage.setText("Please confirm that the information "
    +"entered is correct");
    add(ConfirmMessage, gridBagConstraints1);
    // Gather Info to display to user for confirmation //
    final JTextArea log = new JTextArea(10,35);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    log.append("Name: " storeInfoRef.getFirstName() " "
    +storeInfoRef.getLastName() );
    log.append("\nTest Project: " +storeInfoRef.getTestProject() );
    log.append("\nTest Director: " +storeInfoRef.getTestDirector() );
    log.append("\nTest Location: " +storeInfoRef.getTestLocation() );
    log.append("\nDate: " +storeInfoRef.getDate() );
    String fileOutput = "";
    Vector temp = new Vector( storeInfoRef.getFiles() );
    for ( int v=0; v < temp.size(); v++ )
    fileOutput += "\n " +temp.elementAt(v);  // Get File Names
    log.append("\nFile: " +fileOutput );
    // log.repaint();
    // log.validate();
    // log.revalidate();
    JScrollPane logScrollPane = new JScrollPane(log);
    System.out.println("Name: " storeInfoRef.getFirstName() " " +storeInfoRef.getLastName() );
    System.out.println("Test Project: " +storeInfoRef.getTestProject() );
    System.out.println("Test Director: " +storeInfoRef.getTestDirector() );
    System.out.println("Test Location: " +storeInfoRef.getTestLocation() );
    System.out.println("Date: " +storeInfoRef.getDate() );
    System.out.println("File: " +fileOutput );
    // End of Gather Info //
    add(logScrollPane, gridBagConstraints1);
    PrevButton.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    PrevButtonMouseClicked(evt);
    PrevButton.setText("Back");
    JPanel Buttons = new JPanel();
    Buttons.add(PrevButton);
    add(Buttons, gridBagConstraints1);
    // If User Presses 'Prev' Button //
    private void PrevButtonMouseClicked(java.awt.event.MouseEvent evt) {
    try
    currentFrame.setVisible(false); // Hide this Frame
    prevFrame.setVisible(true); // Show Next Frame/Screen of Program
    catch ( Throwable e ) // If A Miscellaneous Error
    System.err.println( e.getMessage() );
    e.printStackTrace( System.err );
    }// End of Confirmation class

  • How to put a Jpanel always over a JtextArea ?

    I want to have a little Jpanel above a JTextArea.
    At the initialize section, I add first the Jpanel and after the JtextArea (both in a 'parent' Jpanel with null layout)
    When I run the program I see the Jpanel over the JtextArea, but when I write on it and it reaches the area when the Jpanel is placed, the JtexArea brings to front and the Jpanel is no longer visible.
    So, how can I have my Jpanel on top always ?
    And another question , is there a hierarchy that control that I Jpanel is always over a Jbutton (even if the initial z-order of the button is higher than the Jpanel's)
    Thanks
    ( I do not send any code because it is so simple as putting this two components into a Jpanel)

    tonnot wrote:
    And another question , is there a hierarchy that control that I Jpanel is always over a Jbutton (even if the initial z-order of the button is higher than the Jpanel's)JLayeredPane
    ( I do not send any code because it is so simple as putting this two components into a Jpanel)Try it with a JLayeredPane and if you still have problems, post a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://mindprod.com/jgloss/sscce.html].
    db

  • 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.

Maybe you are looking for

  • How do i add my personal e-mail account?

    How do I add my personal e-mail account to my iphone?

  • Help Nokia N8 prob. !

    need help nokia N8 my new nokia N8 was working brilliantly until software update ! now i cannot customise screensaver. i was able to use my own screensaver [gif] file but now the option does not appear, the only options i see are none, music player,

  • Slideshow Editing

    Is there a way to edit the layout of the photos in a slideshow while using the "Reflections" theme?  For example, I would like 2 photos instead of 3 to show on screen.

  • How do you un-install without a disc?

    I have a mac BookPro i bought Feb 2011and never updated the OS, until i bought Mountain Lion and for some reason it's not going to port over anything from iPhoto, which is about 2k pictures etc.  i want to uninstall the OS and i do not believe i have

  • RSR_OLAP_BADI Compute method is not trigerred

    Hi there, I have a problem with RSR_OLAP_BADI used for Virtual characteristics. I have defined the BADI based on the defention RSR_OLAP_BADI. I followed the following steps. 1-Created my implementation based on RSR_OLAP_BADI. 2-Created my virtual cha