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.

Similar Messages

  • How add the Jlabel in Jtooltip

    Hi,
    here i am trying to add the toll tip for Jlabel. But that popup should display like below. can any one help on this.
    This is my box
    • sample
    • sample
    • sample

    Use HTML.
    db

  • Add & update JLabels

    Hello guys,
    My problem is: I got a JLabel with an image that is showed in the panel when I start the application. Then if the user clicks on a button, the JLabel must be replaced by another one.
    I know about Event Handling, as you can see below. I'm confused about what JPanel Methods I should use to print on screen the new JPanel.
    Heres a sample of my code (this file is not the main one..it is involked by another one):
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    public class Simples extends JFrame implements ActionListener
    public JFrame frame = new JFrame();
    public JButton cg = new JButton();
    public Simples()
         //Panel and JLabel
         final JPanel panel = new JPanel();
         final JLabel label1 = new JLabel ("LABEL_BEFORE_CLICKS);
    pane.add(label1);
    //JButton
    JButton start = new JButton ("Start");
    frame.getContentPane().add(panel, BorderLayout.CENTER);
         frame.pack();
    frame.setVisible(true);
    //events
         start.addActionListener(
         new ActionListener()
    {      public void actionPerformed(ActionEvent e)
         { cg = (JButton)e.getSource();
    JLabel label1 = new JLabel ("LABEL AFTER CLICKS");
    panel.add(label1);
    panel.remove(label1); /* IS THIS WRONG? WHAT SHOUD I DO HERE TO GET THE NEW LABEL DISPLAYED OVER THE OLD ONE?*/
    frame.pack();
    frame.repaint();

    When you are changing a label don't worry about adding a new label in it's place just change the label that is already there with it's setText and setIcon methods. That way you don't have to remove and then add a new JLabel with is redundant anyway.

  • How to add blank line below the table/row whenever there is no data

    Hello Everyone,
    I have a table in my report template like below:-
    Children / Dependents: Name / Comments: Grandchildren: Name / Comments:
    Son John Daughter Smith
    Daughter Laura Son Kevin
    Son Bill None NA
    When i run the report I need to achieve the following conditions:-
    Condition 1: Loop through all rows and whenever there is data in any row in the table...I need to Populate and print it.
    Condition 2: When Loop is ended, when you see there is no data in any row in the table... add a dash line at the end of the table.
    Condition 3: Total no of populated rows + blank dash line <= Max no of rows in DB. And when max no of populated rows in report = max no of rows in DB/UI ... don’t print dash line.
    I want to achieve these conditions. Can you please help me.
    Thanks..Rithesh

    Hello Everyone,
    I have a table in my report template like below:-
    Children / Dependents: Name / Comments: Grandchildren: Name / Comments:
    Son John Daughter Smith
    Daughter Laura Son Kevin
    Son Bill None NA
    When i run the report I need to achieve the following conditions:-
    Condition 1: Loop through all rows and whenever there is data in any row in the table...I need to Populate and print it.
    Condition 2: When Loop is ended, when you see there is no data in any row in the table... add a dash line at the end of the table.
    Condition 3: Total no of populated rows + blank dash line <= Max no of rows in DB. And when max no of populated rows in report = max no of rows in DB/UI ... don’t print dash line.
    I want to achieve these conditions. Can you please help me.
    Thanks..Rithesh

  • How to add video track below v1 ?

    Hi all experts,
    It is driving me nuts figuring out these.
    I have a reasonable big project file in the sense that there are many pictures & videos stack on top of each other.
    Now I want to add a video track to the most bottom layer (ie below track v1). How do I do that ? When I dis a right click to "Add track", it automatically adds track to the top !!
    At the moment I have to select everything & move up so that I have a clear track at the very most bottom. In so doing, I sometimes missed out some clips & it got messed up.
    It would be good if there is a way to add track below v1.
    Any ideas ?
    Thank you
    Cheers

    Thanks Tom,
    This saves me lots of tedious work !!
    Cheers

  • Add anchor directly below another to same selection?

    Hi all. Got a maddening problem I thought would have a more obvious solution.
    I want to connect selected end points on two anchors that share X and Y coordinates.
    1. Selecting the anchor with the lower Z-index and trying to select the higher one will not work because of selection localised bias or whatever you want to call it either way clicking on the same location again will take me to be referring to the same anchor I already have selected.
    2. Selecting one anchor and hiding its parent path to unambiguously reveal the other doesn't work because hiding an object removes it from selection.
    3. The save selection tool looked promising but unlike its Photoshop cousin, its most advanced feature is the 'edit selection' property and the height of its powers involves changing the name of a saved selection.
    Any advice?

    Instead of trying to select the two coincident endpoints by clicking, select them by dragging a marquee selection
    around them.
    Also understand: If the two endpoints are on the same path, you don't have to select them at all to close the path. Just select the whole path (as the black pointer would), and invoke the Join command (Ctrl J).
    JET

  • 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

  • Add a bullet correctly below the text in the previous line.

    Hi All,
    I know how to add bullets in a word doc, but I dont know how to set the range.listformat.leftindent property to match this particular reuirement i.e
    1.1.1.   some text 
               (add a bullet below s in some)
    normal text
    (add a bullet below n) 
    i.e check where start of the text is , in the previous line add a bullet right below this text dynamically

    Hi Apoorva,
    I'm not quite sure what your uiquirement is, seems that you want to insert a sub-level bullet below the previous paragraph. You can use this method to create a sub-level bullet in the word document.
    Range.ListFormat.ListIndent
    For example:
    Application app = new Application();
    app.Visible = true;
    Document doc = app.Documents.Add();
    Paragraph para= doc.Content.Paragraphs.Add();
    Range rng = para.Range;
    para = doc.Content.Paragraphs.Add();
    para.Range.ListFormat.ApplyBulletDefault();
    para.Range.InsertBefore("test1");
    para = doc.Content.Paragraphs.Add();
    para.Range.ListFormat.ApplyBulletDefault();
    //para.Range.ListFormat.ListOutdent();
    para.Range.ListFormat.ListIndent();
    para.Range.InsertBefore("test2");
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Add Icon to a JTextArea

    Hola a todos,
    I want to add an icon to a JTextArea. How can I do that?
    Chao
    Juergen

    With the JTextPane and the method
    insertIcon(Icon g);
    I can insert an icon but only at the end. I want to have the icon at the beginning of the line.
    The text is set by:
    setText(....);
    I think the text overrides the icon. How can I add the text behind the icon?
    setText (valor.toString());
    insertIcon(new ImageIcon("libro1.gif"));
    Then I have the Text and the icon behind.
    insertIcon(new ImageIcon("libro1.gif"));
    setText (valor.toString());
    Then I do only have the text.
    Does anybody know why?
    Chao
    Juergen

  • IPad 2/Numbers How-To Add Row Below

    I'm creating an invoice sheet that I'd like to add like I do in Numbers in OSX
    In Numbers on OSX I just press the ALT-Down Arrow to create a row below the previous product line item.
    I'm trying to figure out a way to accomplish this on the ipad 2 using iOS 5 and Numbers
    For example, in the image attached, I want to add a productname2 below Product Name Here line.
    Thanks

    The easiest way is to use the iPad Numbers Form feature.
    At the top of the sheet find the "+" tab and tap it. Select new form and base it on the table that you use for the invoice.
    If your table is anything like the Invoice Template that came with Numbers, a Form will be created that allows line entry into your table and when you get to the bottom of the invoice list of products will creates a new row. (Use the "+" on the bottom of the form to make new items.
    The footer calculations should include the new row's data automatically.
    Good luck.

  • Illegal component position when add JLabel to JtextPane

    Hi all,
    I want to add a JLabel to a JTextPane, the label shoud be put in the lines of text just like the normal text. I have some questions:
    1. How can I put the label in the position we want, when I use the method add(label, textPane.getStyledDocument().getLength()), it generates exception :"illegal component position"
    2. How can I set the width and the height of the label so that user cannot know that I used the label. I mean the text on label and the normal text on JTextPane must look the same. Of course I know the length of the caption of the label
    Thank you very much

    How can I put the label in the position we want, I'm not sure you can add a component using that method. I think there is an insertComponent(...) method to use. Also you may need to make the text pane uneditable first if I remember correctly. Something like:
    textPane.setEditable(false);
    textPane.insertComponent(...);
    textPane.setEditable(true);
    How can I put the label in the position we want, label.setFont(textPane.getFont());

  • IPad 2, Numbers - Add row below

    I'm creating an invoice sheet that I'd like to add like I do in Numbers in OSX
    In Numbers on OSX I just press the ALT-Down Arrow to create a row below the previous product line item.
    I'm trying to figure out a way to accomplish this on the ipad 2 using iOS 5 and Numbers
    For example, in the image attached, I want to add a productname2 below Product Name Here line.
    Thanks

    The easiest way is to use the iPad Numbers Form feature.
    At the top of the sheet find the "+" tab and tap it. Select new form and base it on the table that you use for the invoice.
    If your table is anything like the Invoice Template that came with Numbers, a Form will be created that allows line entry into your table and when you get to the bottom of the invoice list of products will creates a new row. (Use the "+" on the bottom of the form to make new items.
    The footer calculations should include the new row's data automatically.
    Good luck.

  • Using JTextArea - How do I clear it?

    Hi all.
    I have written a GUI program which transfers data from a method to a JTextArea/JScrollPane upon a button ActionEvent.
    When I press the "Next Record" button I want to be able to clear the previous details held in this JTextArea before I print the new ones in it. The Same for going backwards through an array. Does anybody know how to do this?
    Currently I am using the append method to add the returned String to my JTextArea. I have also tried using a replaceRange(String, int, int) method to clear the box before printing new details, but this isn't working properly as each Record in the array contains a different String length, so I can not enter the int values for each specific object.
    Below is the code for the application, and I've highlighted where I have used the methods to add a String to the JTextArea. I'm declaring the class for the action event within creating the actionListener, but can seperate it out if people need to see it more clearly.
    RECORDING CLASS ----------
    package RecordingManagerGUI;
    public class Recording
    private String title, artist, genre;
         public Recording (String theTitle, String theArtist, String theGenre)
              title = theTitle;
              artist = theArtist;
              genre = theGenre;
            public String getAlbum()
                return title;
            public String getArtist()
                return artist;
            public String getGenre()
                return genre;
         public String toString()
              String s = "Title: " + title + "\nArtist: " + artist + "\nGenre: " + genre + "\n\n";
              return s;
    }MANAGER CLASS ---------------
    package RecordingManagerGUI;
    import java.util.*;
    public class Manager
    private Recording[] theRecordings;
    private int numRecordings, maxRecordings, age;
    private String managerName;
    //Extending the Manager Class Instance Variables
    private int current = 0;
    private String record;
         public Manager (String theName, int theAge, int max)
              managerName = theName;
                    age = theAge;
              maxRecordings = max;
              numRecordings = 0;
              theRecordings = new Recording[maxRecordings];
         public boolean addRecording (Recording newRecording)
              if (numRecordings == maxRecordings)
                   System.out.println("The store is full");
                   return false;
              else
                   theRecordings[numRecordings] = newRecording;
                   numRecordings++;
                   return true;
            public int nextRecording ()
                if(current < numRecordings)
                    current += 1;
                else
                    record = "You have reached the end of the Records"; //initialise the string if no records
                return current;
            public int previousRecording()
                if(current > 1)
                    current -= 1;
                else
                    record = "You have reached the start of the Records"; //initialise the string if no records
                return current;
            public String displayCurrent()
                String displayRec = "";
                displayRec += theRecordings[current-1];
                return displayRec;
         public void displayDetails()
              System.out.println("Manager Name: " + managerName + ", " + age);
         //public void displayRecordings()
         //     System.out.println("\nThe Recordings: ");
         //     for (int i = 0; i < numRecordings; ++i)
         //          System.out.println(theRecordings);
    }RecordingManagerGUI CLASS ----------/*
    *Need to add a Label which tells me when I have reached the end of the Records
    package RecordingManagerGUI;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class RecordingManagerGUI extends JFrame {
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    JButton nextRecord;
    JButton previousRecord;
    JLabel recordLabel;
    JTextArea displayRecord;
    Manager theManager;
    public RecordingManagerGUI() {
    //Create and set up the window.
    super("Recording Manager Application");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Recording FooFighters = new Recording("The Colour and the Shape", "Foo Fighters", "Rock");
    Recording BlindMelon = new Recording("Blind Melon", "Blind Melon", "Alternative Rock");
    Recording JoeSatriani = new Recording("The Extremist", "Joe Satriani", "Instrumental Rock");
    Recording PercySledge = new Recording("When a Man Loves a Woman", "Percy Sledge", "Soul");
    Recording JustinTimberlake = new Recording("Justified", "Justin Timberlake", "Pop");
    Recording BeyonceKnowles = new Recording("Dangerously in Love", "Beyonce Knowles", "R'n'B");
    Recording TupacShakur = new Recording("2Pacalypse Now", "Tupac Shakur", "Hip Hop");
    theManager = new Manager("Cathy", 42, 7);
    theManager.addRecording(FooFighters);
    theManager.addRecording(BlindMelon);
    theManager.addRecording(JoeSatriani);
    theManager.addRecording(PercySledge);
    theManager.addRecording(JustinTimberlake);
    theManager.addRecording(BeyonceKnowles);
    theManager.addRecording(TupacShakur);
    displayRecord = new JTextArea(10, 30);
    displayRecord.setEditable(false);
    JScrollPane recordScroll = new JScrollPane(displayRecord);
    recordLabel = new JLabel("Record Details");
    nextRecord = new JButton("Next Record");
    nextRecord.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){theManager.nextRecording();displayRecord.append(theManager.displayCurrent());displayRecord.replaceRange(theManager.displayCurrent(), 0, 30);}}); //ADDING STRING TO JTEXTAREA
    previousRecord = new JButton("Previous Record");
    previousRecord.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){theManager.previousRecording();displayRecord.replaceRange(theManager.displayCurrent(), 0, 30);}}); //ADDING STRING TO JTEXTAREA
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(recordLabel);
    getContentPane().add(recordScroll);
    getContentPane().add(nextRecord);
    getContentPane().add(previousRecord);
    //Display the window.
    pack();
    setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    new RecordingManagerGUI();
    }Would appreciate any help thanks. I'm not sure if I just need to create a new instance of the JTextArea upon the event which would hold the String information. If so I'm not really sure how to do this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I don't know, the Swing experts are in the Swing forum. but setText() is defined in TextComponent, which a JTextArea is.

  • JButtons in a JTextArea

    I am hoping to add a JButton to a JTextArea, but to be completely honest, I am not sure if this is physically possible, let alone feasible.
    I have written some code which I hoped would do the trick, and although it compiles, it does not display the JButton.
    Any help, starting with, am I asking the impossible would be greatly appreciated.
    Below is my method:
    public void displayMatchedManagers(Vector vmd)
    JButton jbNP[]= new JButton[vmd.size()];
    JButton jbNM = new JButton("New Manager");
    String details;
    jtaManagerFeedback.append(" ***FEEDBACK***" +
    "\n\n The system has found some possible" +
    "\n matches to the criteria just entered, it" +
    "\n is therefore possible that this manager" +
    "\n has already registered." +
    "\n\n Look at the existing managers details" +
    "\n below, and if a match is found click the" +
    "\n 'New Prediction' button beneath the" +
    "\n relevant manager's details. This will add" +
    "\n the prediction to the manager's account." +
    "\n\n ***POSSIBLE MATCHES***\n\n");
    for ( int i = 0; i < vmd.size(); i++ )
    MD = (ManagerDetails) (vmd.elementAt(i));
    details = " Manager \\ Prediction ID: " + MD.getIDNumber() +
    "\n Name: " + MD.getFirstName() +
         " " + MD.getLastName() +
         "\n Address: " + MD.getAddress() +
    "\n Postcode: " + MD.getPostcode() +
         "\n Area Code: " + MD.getAreaCode() +
         "\n Telephone Number: " + MD.getTelephone() +
         "\n Mobile Number: " + MD.getMobile() +
         "\n E-mail Address: " + MD.getEmail() + "\n\n";
    jtaManagerFeedback.append(details);
    jtaManagerFeedback.add(jbNP[i] = new JButton("New Prediction"));
    details = "\n\n If none of the above managers where a" +
    "\n match, click the 'New Manager' button below." +
    "\n This will add the new manager to the" +
    "\n database along with their predictions.";
    jtaManagerFeedback.append(details);
    jtaManagerFeedback.add(jbNM);
    jtaManagerFeedback.setCaretPosition( 0 );
    Thanks, Kris Dowse

    found it..
    //initialize the gridbaglayout
    gridbag = new GridBagLayout();
    c = new GridBagConstraints();
    keuzes.setLayout(gridbag);
    c.fill = GridBagConstraints.NONE;
    c.gridwidth = GridBagConstraints.REMAINDER;      //end row
    c.insets= new Insets(3,10,3,10);
    //     c.ipadx = 20;
    //     c.ipady = 5;
    introtext=new JLabel("Welkom bij ZKK-DOS maak uw keuze")
         public Dimension getPreferredSize()
              return new Dimension(800,80);
    introtext.setHorizontalAlignment(JLabel.CENTER);
    configuratie = ZKKDOSConfigManager.getConfiguration();
    if(configuratie.containsKey("HMopt"))
    //some stuff to read my ini file
    Vector options =(Vector)configuratie.get("HMopt");
    String confItem=(String)options.elementAt(0);
    System.out.println(confItem);
    // the aantal variable holds the number of buttons i want
    int aantal = Integer.parseInt(confItem.substring(confItem.length()-1));
    //keuzes.setLayout(new GridLayout(aantal,1));
    for(int i=0;i<aantal;i++) // loop as many times as we want buttons
    //set the gridbag the way i wanted the buttons
    c.gridwidth = GridBagConstraints.REMAINDER;
    //get the buttons caption from my ini file
    Button b = new Button((String)options.elementAt(i+1))
    // an inner class to make sure the buttons get the size i want them to be as layoutmanager uses getPreferredSize() to get the buttons preferredSize
      public Dimension getPreferredSize()
       return new Dimension(80,30);
    b.addActionListener(this);
    b.addMouseListener(this);
    //add the button to the gridbaglayout
    gridbag.setConstraints(b, c);
    keuzes.add(b);
    }hope it helps you,
    robert

  • How to add buttons/text to right pane when selection is made from left pane

    Hi,
    I am new to JAVA development with SWING.
    I am trying to create an application where in the left pane there is a Tree Menu and in the right pane I have some buttons. Based on the selections in the left Pane, I should be able to add more buttons and or text to the right pane.
    How do I accomplish this? If you guys have any sample code, Please post it or suggest different ways of accomplishing.
    Thanks in advance.
    user2325986

    It looks like you are declaring different main_Frame, rightPane and leftPane and have too many items static and final. Take a look at the code below. I have set GridBagLayout for the frame for a better look.
    I am not sure what you mean when you say that you want right panel only and want to add to it. Also, I think you would be better off using CardLayout for rightPanel as stated by jduprez
    When you want to show code use {_code_} code here {_code_} tags (code in brackets without underscores)
    Here is a working sample of what you had:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import javax.swing.tree.*;
    public class Main
        public static void main(String[] args)
            main_Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            main_Frame.setVisible(true);
        public static TestFrame main_Frame = new TestFrame();
    class TestFrame extends JFrame
        public TestFrame()
            setTitle("Test Frame");
            setSize(500, 500);
            setLayout(new GridBagLayout());
            leftGBC = new GridBagConstraints();
            leftGBC.gridx = 0;
            leftGBC.gridy = 0;
            leftGBC.fill = leftGBC.BOTH;
            leftGBC.weightx = 10;
            leftGBC.weighty = 100;
            rightGBC = new GridBagConstraints();
            rightGBC.gridx = 1;
            rightGBC.gridy = 0;
            rightGBC.fill = rightGBC.BOTH;
            rightGBC.weightx = 100;
            rightGBC.weighty = 100;
            leftPanel = new JPanel();
            leftPane = new JScrollPane(leftPanel);
            leftPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            leftPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            rightPanel = new JPanel();
            rightPane = new JScrollPane(rightPanel);
            rightPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            rightPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("main_Tree");
            DefaultMutableTreeNode Branch1 = new DefaultMutableTreeNode("Branch1");
            DefaultMutableTreeNode Leaf1 = new DefaultMutableTreeNode("Leaf1");
            root.add(Branch1);
            Branch1.add(Leaf1);
            DefaultMutableTreeNode Branch2 = new DefaultMutableTreeNode("Branch2");
            DefaultMutableTreeNode Leaf2 = new DefaultMutableTreeNode("Leaf2");
            root.add(Branch2);
            Branch2.add(Leaf2);
            JTree tree = new JTree(root);
            tree.setRootVisible(true);
            tree.setShowsRootHandles(true);
            tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
            tree.addTreeSelectionListener(new TreeSelectionListener()
                public void valueChanged(TreeSelectionEvent se)
                    JTree tree = (JTree) se.getSource();
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                    if (node == null) return;
                    String nodeInfo = node.toString();
                    if (nodeInfo.equals("Leaf1"))
                        rightPanel = new JPanel();
                        rightPanel.add(label);
                        Main.main_Frame.remove(rightPane);
                        rightPane = new JScrollPane(rightPanel);
                        rightPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                        rightPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                        Main.main_Frame.add(rightPane, rightGBC);
                        Main.main_Frame.validate();
                        Main.main_Frame.repaint();
                    if (nodeInfo.equals("Leaf2"))
                        rightPanel = new JPanel();
                        rightPanel.add(Jbt2);
                        Main.main_Frame.remove(rightPane);
                        rightPane = new JScrollPane(rightPanel);
                        rightPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                        rightPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                        Main.main_Frame.add(rightPane, rightGBC);
                        Main.main_Frame.validate();
                        Main.main_Frame.repaint();
            DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
            tree.setRowHeight(30);
            renderer.setLeafIcon(new ImageIcon("blue-ball.gif"));
            renderer.setOpenIcon(new ImageIcon("red-ball.gif"));
            renderer.setClosedIcon(new ImageIcon("yellow-ball.gif"));
            renderer.setFont(new Font("Monospaced",Font.BOLD|Font.ITALIC,15));
            renderer.setTextNonSelectionColor(Color.blue);
            renderer.setTextSelectionColor(Color.white);
            renderer.setBackgroundNonSelectionColor(Color.white);
            renderer.setBackgroundSelectionColor(Color.gray);
            renderer.setBorderSelectionColor(Color.lightGray);
            leftPanel.add(tree);
            add(leftPane, leftGBC);
            add(rightPane, rightGBC);
        private JPanel leftPanel;
        private JPanel rightPanel;
        private JScrollPane leftPane;
        private JScrollPane rightPane;
        private GridBagConstraints leftGBC;
        private GridBagConstraints rightGBC;
        private JButton Jbt1 = new JButton("Button1");
        private JButton Jbt2 = new JButton("Button2");
        private JLabel label = new JLabel("Enter your message below");
        private JTextArea jta = new JTextArea(10,15);
        private JButton Jbt3 = new JButton("Button3");
        private JButton Jbt4 = new JButton("Button4");
    }

Maybe you are looking for

  • Firefox always opens all tabs that were opened when last closed

    Firefox, out of the blue, started to always show my tabs from the last session when it is started. I checked that Firefox not listed in the task manager list after closing. So I tried the following: - changing the option "when Firefox starts" to all

  • Adobe Widget browser "Google Map" Search box for address

    First of all I would like to thank Zizzer Zazzer for this google map. I ts really very helpful for the website. I was wondering if this is possible to add text search box for the address in google map? I was trying my self and tried with geocode with

  • Error code meaning in hardware test

    I have had problems recently and finally discovered an error when running hardware test. Can anyone tell me what the error means - it is obviously a dimm memory problem but what else does it tell me? error code = 2MEM/1/4:DIMM6/J43 THANKS PAUL

  • Parallely Insert Multiple Rows into an Iterator

    Hi, I'm facing a scenario where I have to enter data into multiple rows of an iterator in parallel, where each row is represented as an af:panelFormLayout on the UI, the number of rows being determined at runtime, by user input. I've got a java-based

  • Apple ethernet thunderbolt vs usb adapter

    Which one is faster?? which one should i get??