JTabbedPane and JTextArea

I have a problem, and I can't find what I need.
I have an application that is suppose to be an address book. I've created 26 tabs (lettered A - Z) and in each tab, I've placed a JPanel (e.g. panelA, panelB, etc) and on each panel I've placed a JTextArea and a JList . I load my data from a file into a Vector.
Here's my dilemma, I don't know how to get my data from my Vector to my JTextArea or my JList. If I instantiate a new JList and place it on the tab, it adds it as a new JList.
I can get the tab via getSource(), but I don't know how to access the JTextArea or the JList in the tab.
I can sort my Vector, print it out via System.out.println's, shoot, I can even pull out specific elements that correspond to a specific letter (the person who's last name starts with "M" for instance), but getting it into the JList or putting it in the JTextArea eludes me. Any help would be greatly appreciated.

1) Create a custom panel (MyAddressPanel). Add the JList and JTextArea to the Panel
2) Create a couple of accessor method (getAddressList, getAddressTextArea) to access any component you add to the panel
3) Add each panel to the tabbed pane
Now whenever you want to access the data from a specific tab you would do something like:
int selected = tabbedPane.getSelectedIndex()
MyAddressPanel panel = (MyAddressPanel)tabbedPane.getComponentAt(selected);
JList list = panel.getAddressList();
...

Similar Messages

  • JTextField and JTextArea don't get focus occuasionally

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

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

  • JTabbedPane and InsertTab method

    Hi at all!!!Sorry for my bad english!!
    For a university project I want to implement a copy of notepad. Only I want to manage a more document and I think that it is possible through the JTabbedPane and it works.
    But I don't know how I can implement a button that add/remove a tab during the runtime.
    Is there someone that can help me???
    thank u
    giuliano

    Your main window should have [AddNewTab] and [RemoveTab] buttons.
    In their event handler, launch a dialog and accept required user inputs.
    After you dispose the dialog, call JTabbedPane#add(), addTab() or remove().

  • JTabbedPane and removeTabAt() method

    Hello,
    I use in my application a JTabbedPane and i want allow the user to remove a tab of this JTabbedPane. When the JTabbedPane change i need to perform some traitement.
    So i use a ChangeListener to be informed of all changes of my JTabbedPane.
    But, when i removed a tab which is not in last or first position i'm not informed by the change.
    Thanks for your help.
    Guiguch

    I had the same problem. I fixed it by overriding the remove() method to fire a StateChanged event:
    tabbedPane = new JTabbedPane()
         public void remove(int tab)
              super.remove( tab );
              int after = getSelectedIndex();
              //  The selected tab remained the same after this remove, consider
              //  it a state changed
              if (after == tab)
                   fireStateChanged();
    };

  • How to make a frame with components and JTextAreas on it?

    on the Window 98 System, when you press F1 on the keyboard, you will get a window(frame) where there are "buttons" and "textAreas".
    i would like to create a JFrame like that, but how to realize it?
    thanks a lot!!!

    What do you want to do?
    You can easily create a JFrame, and then create JButtons and JTextAreas and then add() them to the JFrame's content pane.
    But you must know that already, so it must be something different you are confused about. What is it?

  • JTabbedPane and focus problem.

    Hello. I currently have a JTabbedPane which contains the various panels that make up different tabs. These tabs are extensions of panels, and are seperate classes imported into the class which contains my JTabbedPane and then added. The frame which conatins my JTabbedPane also has a button, which when pressed I wish it to look at the tab which is currently active, and call a method from the class which this tab refers to. The problem is that I don't know how to get my button to determine which tab is currently active. Any help will be gratefully recieved.

    Use getSelectedComponent() or getSelectedIndex() of your JTabbedPane object.

  • JTabbedPane and one Button for all Tabs

    Hello everybody,
    im new here an would say HELLOOO to everyone
    So ive got an issue.
    I am creating in "class A"  tabs for a JTabbedPane. In "class B" i create the JTabbedPane and creat instances of class A and add them to the TabbedPane.
    in Class B i also create a button, for save actions. When i click the button, a method "save()" will be called and read from every tab the Strings out of textfields.
    My problem now is, that it dont work, i call the save method with the instance from the tab, but it dont getText() from the textfield.
    For example:
    //create an instance tab, parameter is the save file
    Tab myTab = new Tab(file);
         //other code
    (Tab)myTab.save(); //here i eclipse cast to Tab automatically
    the save-Method in class A (Tab):
    save() {
    sysout(texfield1.getText)
    BTW how can i highlight code in this forum?

    You can add syntax highlighting by going into the advanced editor, that will add a button for it. Unfortunately there are no quick code tags :/
    After you find the button post your ACTUAL code. not just some random snippet which looks like your code. What you posted doesn't even compile.

  • JTabbedPane, and JPanel.

    Hi im going thrue swing tutorials here on sun. And wonder a bit about hierarchy. I use JTabbedPane and every class have there own JPanel that i add to the extended JPanel. I show below with example.
    In Main class
      public JFrame mstFrame() {
            JFrame frame = new JFrame("Main Frame");
            JTabbedPane mstPane = new JTabbedPane();
            mstPane.addTab("Start", new StartPage());
            frame.add(mstPane);
            frame.setVisible(true);
            return frame;
        }In StartPage Class
    public class StartPage extends JPanel {
        JPanel createProjectPanel = new JPanel(new GridBagLayout());
         GridBagConstraints c = new GridBagConstraints();
         JScrollPane createCustomerPane = new JScrollPane();
         c.gridy = 1; // second row
         c.gridx = 0; // first cell
         createProjectPanel.add(createCustomerPane ,c);
    add(createProjectPanel);Does this destory the hierarchy, or is it okey to do it this way?

    It makes sense to have each tab represented by a panel, so I don't reallly understand the question.
    public class StartPage extends JPanel
        JPanel createProjectPanel = new JPanel(new GridBagLayout());
        add( createProjectPanel );However, it is unecessary to create a second panel since your class already extends JPanel. Just add the scrollPane directly to the class.
    setLayout( new GridBagLayout() ):
    JScrollPane createCustomerPane = new JScrollPane();
    add(createCustomerPane, c);

  • Using JCheckBox, JButton and JTextArea with JDBC

    Hello shlumph and SoulTech2012.
    thanks for the reply. I�m wondering do any of you have links to web pages that include tutorials and source code on using JCheckBox, JButton and JTextArea with JDBC. would any of you who have experience with using JCheckBox, JButton, JTextArea and JDBC together be able to give me a few tips on how to select certain data from a table using JCheckBox, JButton and display the data in a JTextArea? examples of such data could be CD/DVD/Game data - i want users of my video library system to be able to view CD/DVD/Game information by name, age category, type and year. Users should be able to click on a check box (e.g. view by name, age category, type or year) and press a button. What would happen then is that data from the Product table would appear in the text area (which could be placed beneath the check box + button inside a frame and/or panel).
    Thank you very much for your help.

    Quit triple posting and cross posting your questions all over the forum. You already have a posting in this forum on this topic and another posting in the Swing forum and another posting in the Programming forum.

  • Regarding_Height in JSplitPane in which JList And JTextArea

    Hi All,
    I have JSplitPane in which two components Jlist and JTextArea
    placed . Here when I type the text in JTextArea respective row no
    is appeared in JList.Here my problem is how to set the row hieght
    of both JTextArea and JList to equal size ....
    Can any body have the idea pls help me.
    Thanks in advance

    have you experimented with JTextArea's getRowHeight() and
    JLists's get/setFixedCellHeight()?

  • JTabbedPane and JScrollPane

    I am trying to add a JScrollPane inside a tab in a JTabbedPane.. unsuccessfully
    the JScrollPane has a JTextArea added to it...
         // tp previously declared as a JTabbedPane....
        JScrollPane jpC = new JScrollPane();
        JTextArea jtC = new JTextArea(--text source--);
        jpC.add(jtC);
        tp.addTab("Constructors",
                  null,
                  jpC,
                  "View all Constructors");on switching to the tab, it is blank.....
    the tab works fine when I simply have a simple JTextArea inside it, but it is not an option
        JTextArea jtC = new JTextArea(--text source--);
        tp.addTab("Constructors",
                  null,
                  jtC,
                  "View all Constructors");essentially what I need is to have a scrollable peice of text in all of my panes.... any idea what might be going wrong?
    I even tried declaring a new container, adding the scrollpane (with the textarea inside) to it and then creating the tab.. same result.. i understand that a tabbedpane can only contain exactly one component, so i thought this might be a work-around...
    thanks in advance,
    K

    Thanks for the quick reply.....
    actually the solution was quite illogical (IMHO!)
    all i had to do was type cast the freaking thing to (Component)!!!!!!!
        JTextArea jtC = new JTextArea(-- text source --);
        JScrollPane jpC = new JScrollPane(jtC);
        tp.addTab("Constructors",
                  null,
                  (Component)jpC,
                  "View all Constructors");again, thanks for the prompt reply!
    Kunal

  • Issue with re-sizing JTable Headers, JTabbedPane and JSplit pane

    Ok, hopefully I'll explain this well enough.
    In my Swing application I have a split pane, on the left hand side is a JTable and on the right hand is a JTabbedPane. In the tabs of the JTabbedPane there are other JTables.
    In order to make the rows in the JTable on the left and the JTable(s) on the right line up, the Table Header of all the tables is set to the size of the tallest (deepest?) table header.
    Hopefully so far I'm making sense. Now to get to the issue. One of the tables has a number of columns equal to the value on a NumberSpinner (it represents a number of weeks). When this value is changed the table is modified so that it contains the correct number of columns. As the table is re-drawn the table header goes back to its default size so I call my header-resize method to ensure it lines up.
    The problem is this: if I change the number of weeks when selecting a tab other than the one containing my table then everything is fine, the table header is re-sized and everything lines up. If I change the number of weeks with the tab containing the table selected, the column headers stay at their standard size and nothing lines up.
    To make things more complicated, I also put System.out.println's in as every method called in the process to obtain the size of the table header. And every println returned the same height, the height the table header should be.. So I'm really confused.
    Could anyone shed any light on this?
    Thanks.

    Okay I managed to solve the problem by explicitly revalidating and repainting the table header.
    Not sure why it wasnt doing it properly for that table when all the others where fine.
    Oh well...

  • System clipboard, AWT TextAreas, and JTextAreas

    This code makes a JApplet with a Swing JTextArea and an AWT TextArea. The JTextArea won't accept pasted text that was copied from another application. The AWT TextArea will. Why is this, and how can I get a JTextArea to accept pasted input?
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    public class TextAreaTest extends JApplet {
         Container cp = getContentPane();
         JTextArea TextIn = new JTextArea("You can't paste from the system clipboard into this box.",4,44);
         JScrollPane aScrollPane = new JScrollPane(TextIn);
         TextArea awtTextIn = new TextArea("Pasting into this box does work!",4,44);
         public void init() {
              cp.setLayout(new FlowLayout());
              cp.add(new Label("Copy some text from another program."));
              cp.add(new Label("Click in the upper box and press Shift+Insert."));
              cp.add(new Label("Why is nothing pasted?"));
              cp.add(aScrollPane);
              cp.add(awtTextIn);
    //<applet width="500" height="240" code="TextAreaTest.class"></applet>

    Thanks for checking this and replying. Pasting into the JTextArea from outside doesn't work for me, even when I'm running the applet locally. Even when I run the applet with appletviewer from the command prompt, I still can't paste from the outside into the JTextArea. If I cut from the TextArea or from an outside application and try to paste into the JTextArea, nothing happens. I can't go the other way either: If I cut from the JTextArea and try to paste into the TextArea, nothing happens. The only cutting and pasting that works with the JTextArea is that if I cut from within the JTextArea, I can paste back into the JTextArea.
    I wonder why pasting works for you and not for me. I'm using the latest JDK (1.4.2_03) and JRE on Windows XP. I have the same behavior on a Windows 2000 machine with the 1.4.1 JRE.

  • JTabbedPane and JScrollPane problem

    Hi all,
    I'm trying to make working JScrollPane into JTabbedPane. I have been trying several times to make it but with no acceptable effects :( I attached below the simple code to show what I'm interested in.
    PANEL1 has its dimension. I'd like to make that the JScrollPane will be active and enabled to roll when user change JFrame size to less than PANEL1 on pane1.
    Please help!
    Thanks for everyone,
    Greetings,
    import java.lang.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class Sample     {
    static JFrame fr;
    static JPanel pane1, pane2, pane3;
    static JLabel AAA, BBB, CCC;
    static JPanel PANEL1;
    static JTabbedPane panel;
    public static void main(String args[])     {
              fr = new JFrame("Sample");
              pane1 = new JPanel();
              pane1.setLayout(null);
              pane2 = new JPanel();
              pane2.setLayout(null);
              pane3 = new JPanel();
              pane3.setLayout(null);
              panel = new JTabbedPane();
              Font myfont1 = new Font("SansSerif",0,20);
              Font myfont2 = new Font("SansSerif",0,15);
              Font myfont3 = new Font("SensSerif",1,15);
              AAA = new JLabel("AAA");
              BBB = new JLabel("BBB");
              CCC = new JLabel("CCC");
              AAA.setFont(myfont2);
              BBB.setFont(myfont2);
              CCC.setFont(myfont2);
              AAA.setBounds(20,20,300,20);
              BBB.setBounds(20,50,300,20);
              CCC.setBounds(20,80,300,20);
              PANEL1 = new JPanel();
              PANEL1.setLayout(null);
              PANEL1.setBackground(java.awt.Color.CYAN);
              PANEL1.setBounds(20,15,250,300);
              PANEL1.add(AAA);
              PANEL1.add(BBB);
              PANEL1.add(CCC);
              pane1.add(PANEL1);
              panel.insertTab("A", null, pane1, null, 0);
              panel.setSelectedIndex(0);
              panel.insertTab("B", null, pane2, null, 1);
              panel.setSelectedIndex(0);
              panel.insertTab("C", null, pane3, null, 2);
              panel.setSelectedIndex(0);
              panel.setBounds(0,0,550,450);
              fr.setLayout(null);
              //fr.setResizable(false);
              fr.setBackground(java.awt.Color.CYAN);
              fr.setForeground(java.awt.Color.CYAN);
              fr.add(panel);
              fr.pack();
              fr.setSize(550, 450);
              fr.setLocationRelativeTo(null);
              fr.setVisible(true);
    }

    Unfortunately no :( Besides, I can't understand at
    all this line:
    JTabbedPane (panel)TabbedPane = ... new
    w JTabbedPane(...).add/insertTab( ... new
    JScrollPane(new JPanel(...)) ... )It's to big cut-off like for me. Can you insert it
    into my Sample?
    Regards and thanks,It's only my "dev speak". Put a ";" and a var name (, ...) whereever needed, and remove some"()".
    (Sorry, normally I don't help dev beginners on so more complex problems, with just an easy answer.)

  • JTabbedPane and generated code

    Hi all -
    I am teaching myself Java etc using the free copy of JSE provided so kindly by Sun, and have run into a speedbump that I can get around, but doesn't make me happy at all. If I create a jTabbedPane object in the GUI and add objects to it, they are always called "Tab1", "Tab2", etc etc. No matter what I do, I can't change these default names to what I want. I have tried editing the source in Notepad to no avail.
    If I change the Pre-Init code property to add tabbed compnents manually, I can have names I actually want to use - but I have to remove the components from the tabbed pane in the GUI editor. If this was the only way to do it, I would immediately throw this product onto the great steaming pile of almost-useful refuse. However, I can't believe that something that fundamental would have been overlooked by the developers.
    There has to be a simple solution. Please help.

    Ref: http://www.netbeans.org/kb/faqs/gui-editor.html#FaqFormSettingTabNames
    How do I set tab names in a JTabbedPane?
    Select the component representing the tab (typically a JPanel) and go to the Layout properties tab in Inspector. You can set tab title here, as well as tooltip and icon. For example, step through the following procedure.
    1. Create a new JFrame.
    2. Drop a JTabbedPane component onto the JFrame in the Form designer window.
    3. Drop a JPanel component onto the JTabbedPane. A tab will appear.
    4. In Inspector select the JPanel, then click the Layout tab for the JPanel.
    5. The Tab Icon, Tab Title, and Tab Tooltip properties will be exposed, and can be modified.

Maybe you are looking for

  • Security options in Forms 9i

    I am using Forms 9i & Reports 9i I have a form screen that is calling multiple reports based on the user selection. How can I maintain the security in Forms?(I mean accessing specific reports to specific users & etc) Please give your suggestions.

  • Zip files in Mail.

    Is there any way to open Zip or other compressed files in Mail on the iphone?

  • In New iTunes how do I play a whole album - stops after first song

    In iTunes 11.0.1 (12) I select Music in upper left of window, select Albums, click on an album, click on > to play and get the first song and then it stops.

  • After Effects CS4 tips

    People have asked for a document that includes all of the After Effects CS4 tips of the day. OK. Here it is.

  • How to change passcode when you dont know it

    Hi there i have changed my passcode but you know when you use fingerprint recognition at all times and than you battery died on you when you started up you have to put passcode in and that is where my problem began. Can somebody tell me how to reset