Insert tab in jTabbedPane problem

Hi,
I am trying to insert a tab into a JTabbedPane using this method:
insertTab(String title, Icon icon, Component component, String tip, int index)
It works fine - the tab is inserted to the right place on the GUI, but the problem is this - though the tab is inserted at the right location in the GUI, when I traverse through the JTabbbedPane, I see that the new tab is inserted at the last index!
Can someone let me know how to fix this problem?
Thanks

Here is the example code:
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
public class TabbedPaneTest {
    public static void main(String[] args) {
        JTabbedPane tp = new JTabbedPane();
        tp.add("tab0", new JPanel());
        tp.add("tab2", new JPanel());
        tp.add("tab3", new JPanel());
        tp.insertTab("tab1", null, new JTextArea(), null, 1);
        for (int i=0; i<tp.getComponentCount(); i++) {
            System.out.println("TabComponent"+i+": "+tp.getComponent(i));
}The output of this test program is:
TabComponent0: javax.swing.JPanel...
TabComponent1: javax.swing.JPanel...
TabComponent2: javax.swing.JPanel...
TabComponent3: javax.swing.JTextArea...
You can see that the JTextArea is not inserted at index 1 as expected.
But I found the solution for this problem myself. If you replace tp.getComponent(i) by
tp.getComponentAt(i) the program output is:
TabComponent0: javax.swing.JPanel...
TabComponent1: javax.swing.JTextArea...
TabComponent2: javax.swing.JPanel...
TabComponent3: javax.swing.JPanel...
and this is what I need!!!

Similar Messages

  • Problem inserting tabs in a multi-column layout

    Hello everybody,
    I've created a three-column document and I want to insert a right-tab at the right edge of each column. While this is easy in colums 1 and 3, there is no way that Pages will let me insert tabs in the central column. Clicking on the ruler produces no results, and in the inspector the space for entering a numeric value for the tabs is greyed out (i.e. non-editable).
    If some of you has experienced any of this before, I'd be curious to know; and if you found a solution, then I'd truly appreciate it if you could share it.
    Thank you in advance,
    Rafael

    Hi fruhulda,
    Thank you so much for the quick reply and your willingness to help!
    Right after posting the message I kept trying, and I've been able to insert the tab that I wanted; to be honest, I don't reckon how I did it, but I believe I deleted all other tabs.
    Anyway, the issue still exists, as you can see in the screenshot below. The blocked text will not accept any more tabs via the inspector The +/- signs are inactive), and clicking on the ruler doesn't help either.
    As I said, maybe the way around this problem is to delete all tabs before creating any new ones for this particular column, but that doesn't look like a very intuitive was of proceeding in Pages (which I use precisely because I hate Word's bloated features).
    Again, than you very much for your interest. Best wishes,
    R.
    Original Pages file here: http://www.mediafire.com/?sv4vbimuz4jorpg

  • Tabbed selection screen problem.

    Hi expert,
    I need some help in creating my selection screen.
    Right now i'm creating a tabbed selection screen as the code below follows.
    PARAMETERS: p_test AS CHECKBOX USER-COMMAND testrun DEFAULT 'X'.
    SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
    PARAMETERS: p_offkdt TYPE sy-datum MODIF ID thr.
    SELECT-OPTIONS: s_konfe FOR p0002-konfe.
    SELECTION-SCREEN END OF SCREEN 100.
    SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
    SELECTION-SCREEN: BEGIN OF LINE,
                       COMMENT 1(20) text-005 MODIF ID yea
                        FOR FIELD p_lowdt,
                        POSITION POS_LOW.
    PARAMETERS: p_lowdt TYPE begda MODIF ID yea,
                p_updt TYPE endda MODIF ID yea.
    SELECTION-SCREEN: END OF LINE.
    PARAMETERS: p_keydt TYPE dats MODIF ID yea.
    SELECTION-SCREEN END OF SCREEN 200.
    SELECTION-SCREEN BEGIN OF SCREEN 300 AS SUBSCREEN.
    PARAMETERS: p_lvdat TYPE dats MODIF ID lv.
    SELECTION-SCREEN END OF SCREEN 300.
    SELECTION-SCREEN: BEGIN OF TABBED BLOCK prog_selection FOR 4 LINES,
                      TAB (20) button1 USER-COMMAND push1,
                      TAB (20) button2 USER-COMMAND push2,
                      TAB (20) button3 USER-COMMAND push3,
                      END OF BLOCK prog_selection.
    Now as I'm using tab and subscreen, therefore i need to initialize the subscreen which i wanted to use which i did in the initialization event.
      prog_selection-dynnr = 100.
      prog_selection-activetab = 'PUSH1'.
    With the above code, my default tab would be screen 100 which is the first tab.
    My problem right now is, after i execute the program, and then i press the back button to go back to the selection screen, the default tab 100 is shown again while i wanted to show the last tab which was picked before the program was executed. Please kindly advise how can i solve this problem.
    Many Thanks!
    -Suwardi Nursalim-

    Hi,
    DATA: V_DYNNR TYPE SY-DYNNR VALUE '0100',
               V_ACTIVETAB(4).
    INITIALIZATION.
      MOVE 'PUSH1' TO V_ACTIVETAB.
    AT SELECTION-SCREEN OUTPUT.
      prog_selection-dynnr = V_DYNNR.
      prog_selection-activetab = V_ACTIVETAB.
    When the user clicks each tab of the tab strip.*
    CASE SY-UCOMM.
       WHEN 'PUSH1'.
            V_ACTIVETAB = 'PUSH1'.
            (rest of your code).
       WHEN 'PUSH2'.
            V_ACTIVETAB = 'PUSH2'.
            (rest of your code).
       WHEN 'PUSH3'.
            V_ACTIVETAB = 'PUSH3'.
            (rest of your code).
    ENDCASE.
    Hope this will help you.
    Regards,
    Smart Varghese

  • Allow operator to insert tabs in string control

    I'm trying to allow an operator to insert tabs in a string control with the keyboards tab button. Nothing happens when the tab button is pushed. I tried Skipping the Control in Key Navigation but that didn't work. This is LV 6.1.

    6.1 does not have filter events (where you can discard the tab click), but you can use the event structure with the key down event and if you detect that the tab was clicked you can add a tab to the string programmatically and then use the Key Focus property to set the focus back to the string. I think you might be able to play with the text properties to get the cusor to the end.
    Of course, you can also use another key and simply tell the operators not to click tab, but that would make for an ackward user experience.
    Try to take over the world!

  • Changing Colors of selected tab in JTabbedPane.

    Do someone has some code that can show how to
    change the color of the selected tab with JTabbedPane.
    I can change the other tabs colors with setBackground and setForeground, setBackgroundAt........ but it is the selected
    tab that will not change from the default grey color.
    thanks

    try this code, it works.
    public class TabBackgroundChange extends JFrame {
    private JTabbedPane tabPane = null;
    public static final Color selTabColor = Color.red;
    Color nonSelectedTabColor = null;
    public TabBackgroundChange() {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch(Exception ex) {
    ex.printStackTrace();
    tabPane = new JTabbedPane();
    tabPane.add("One", new JPanel());
    tabPane.add("Two", new JPanel());
    tabPane.add("Three", new JPanel());
    this.getContentPane().add(tabPane);
    this.setSize(200, 200);
    this.setVisible(true);
    tabPane.addChangeListener(new TabChangeListener());
    tabPane.setSelectedIndex(1);
    tabPane.setSelectedIndex(0);
    public static void main(String[] args) {
    TabBackgroundChange tabBackgroundChange1 = new TabBackgroundChange();
    private class TabChangeListener implements ChangeListener {
    public void stateChanged(ChangeEvent ce) {
    int iSelTab = tabPane.getSelectedIndex();
    Color unSelectedBackground = tabPane.getBackgroundAt(iSelTab);
    for(int i=0; i<tabPane.getTabCount(); i++) {
    tabPane.setBackgroundAt(i, unSelectedBackground);
    tabPane.setBackgroundAt(iSelTab, Color.red);
    }

  • Closable Tab in JTabbedPane

    Hi
    I trying to develop a Closable Tab in JTabbedPane. The close button should appear after/before the tab title all the time (like in JBuilder IDE).
    I know the trick where close button appears when the mouse is in that area, but i want it to be displayed all the time irrespective of the mouse position.
    How i should be able to create this component??
    I am very new to swing please help...
    Thanks for your help...
    -Vinod

    Thanks Stas,
    Your code was really helpfull.
    I've improved it a litte bit. So I'd like to share It.
    To use it, just create a ClosableTabbedPane.
    If you need to change the default action (remove the tab) then use the method setCloseTabAction(CloseTabAction) to change the action.
    Cheers,
    Rafa
    ================================
    The TabbedPaneUI
    ================================
    import java.awt.Color;
    import java.awt.FontMetrics;
    import java.awt.Graphics;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.plaf.basic.BasicTabbedPaneUI;
    public class ClosableTabbedPaneUI extends BasicTabbedPaneUI
         public final static int BUTTON_SIZE = 12;
         public final static int BORDER_SIZE = 3;
         public ClosableTabbedPaneUI()
              super();
         protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect)
              super.paintTab(g,tabPlacement,rects,tabIndex,iconRect,textRect);
              Rectangle rect=rects[tabIndex];
              int yPosition = (rect.height-BUTTON_SIZE)/2;
              int xPosition = rect.x+rect.width-Math.round(BUTTON_SIZE*1.5f);
              g.setColor(Color.BLACK);
              g.drawRect(xPosition,yPosition,BUTTON_SIZE,BUTTON_SIZE);
              g.setColor(Color.black);
              g.drawLine(xPosition+BORDER_SIZE,yPosition+BORDER_SIZE,xPosition+BUTTON_SIZE-BORDER_SIZE,yPosition-BORDER_SIZE+BUTTON_SIZE);
              g.drawLine(xPosition+BORDER_SIZE,yPosition-BORDER_SIZE+BUTTON_SIZE,xPosition+BUTTON_SIZE-BORDER_SIZE,yPosition+BORDER_SIZE);
         protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected)
              return super.getTabLabelShiftX(tabPlacement, tabIndex, isSelected)-BUTTON_SIZE;     
         protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics)
              return super.calculateTabWidth(tabPlacement,tabIndex,metrics)+BUTTON_SIZE;
         protected MouseListener createMouseListener()
              return new MyMouseHandler();
         class MyMouseHandler extends MouseHandler
              public MyMouseHandler()
                   super();
              public void mouseClicked(MouseEvent e)
                   int x=e.getX();
                   int y=e.getY();
                   int tabIndex=-1;
                   int tabCount = tabPane.getTabCount();
                   for (int i = 0; i < tabCount; i++)
                        if (rects[ i ].contains(x, y))
                             tabIndex= i;
                             break;
                   if (tabIndex >= 0)
                        Rectangle rect = rects[tabIndex];
                        int yPosition = (rect.height-BUTTON_SIZE)/2;
                        int xPosition = rect.x+rect.width-Math.round(BUTTON_SIZE*1.5f);
                        if( new Rectangle(xPosition,yPosition,BUTTON_SIZE,BUTTON_SIZE).contains(x,y))
                             if( tabPane instanceof ClosableTabbedPane )
                                  ClosableTabbedPane closableTabbedPane = (ClosableTabbedPane)tabPane;
                                  CloseTabAction closeTabAction = closableTabbedPane.getCloseTabAction();
                                  if(closeTabAction != null)
                                       closeTabAction.act(closableTabbedPane, tabIndex);
                             else
                                  // If somebody use this class as UI like setUI(new ClosableTabbedPaneUI())
                                  tabPane.removeTabAt(tabIndex);
    ======================================
    The Closable TabbedPane
    ======================================
    public class ClosableTabbedPane extends JTabbedPane
         private CloseTabAction closeTabAction = null;
         public ClosableTabbedPane()
              super();
              init();
         public ClosableTabbedPane(int arg0)
              super(arg0);
              init();
         public ClosableTabbedPane(int arg0, int arg1)
              super(arg0, arg1);
              init();
         private void init()
              setUI(new ClosableTabbedPaneUI());
              closeTabAction = new CloseTabAction()
                   public void act(ClosableTabbedPane closableTabbedPane, int tabIndex)
                        closableTabbedPane.removeTabAt(tabIndex);
         public CloseTabAction getCloseTabAction()
              return closeTabAction;
         public void setCloseTabAction(CloseTabAction action)
              closeTabAction = action;
    =========================
    The Action
    =========================
    public interface CloseTabAction
         public void act(ClosableTabbedPane closableTabbedPane, int tabIndex);

  • How to add custom button to Insert tab?

    Hello!
    I want to add my own button to the Insert tab. This is the
    tab where there are buttons like h1, h2, ul, ol etc.
    I often need the code tag, but this tag is not avaible in the
    Insert tab. So how to add a custom?

    Any help?

  • How to set a single tab in JTabbedPane invisible

    Hello,
    I want to set only a single tab invisible out of 9 tabs in JTabbedPane. I can disable the tab but not able to set invisible.
    Thanking you in advance.

    you may use JTabbedPane.removeTabAt(int) method as long as you don't want the tab to appear & when needed use JTabbedPane.insertTabAt(String, Icon, Component, String, int) method.
    as far as i know this is only way to achieve our want. this should help you.
    regards,
    Afroze.

  • Each tab of JTabbedPane has different border color

    Is it possible for the content area of each tab in JTabbedPane to have a different border color? Selecting Tab1 highlights content area of the tabbed pane in yellow, selecting tab2 highlights it in red, etc...
    Thanks

    Thanks for the quick response splungebob. How would I get a reference to the Jpanel of a specific tab? In my case each tab will have a toolbar, so I tried setting the toolbar border yellow, but I still have the default jtabbedpane border color surrounding my yellow bordered toolbar. I would prefer to set the color on the jtabbedpane, so that way the Tab itself does not also have the border going underneath it. For instance, I don't want the border to continue underneath the "my tab" tab, as illustrated below:
       | my tab |
    |                                                  |
    |                                                  |
    ----------------------------------------------------Edited by: 816886 on Nov 30, 2010 7:53 AM

  • Where is the structure option under the insert tab in Dreamweaver?

    I was watching the tutorial of Mike Powers for the Bayside Website and he continually uses the structure option under the insert tab. I can not find where this is at in all of Dreamweaver. Does anyone know where this is at?

    http://helpx.adobe.com/creative-cloud/learn/start/dreamweaver.html
    It is the second video down. At about 1:03 he will talk about selecting the structure option and I really want to because it looks extremely helpful!
    Wyatt Ackerman
    816.559.0664 T • 785.534.0465 M
    [email protected]<https://mail.marketsphere.com/owa/redir.aspx?C=56df372cf3f44f3fa455b8f3864b1b80&URL=mailto %3amekaela.kramer%40marketsphere.com>
    MarketSphere Consulting, LLC
    114 W. 11th Street • Suite 700
    Kansas City, MO 64105
    This email message, including any attachments, is for the sole use of the person to whom it has been sent, and may contain information that is confidential or legally protected. If you are not the intended recipient or have received this message in error, you are not authorized to copy, distribute, or otherwise use this message or its attachments. Please notify the sender immediately by return email and permanently delete this message and any attachments. MarketSphere makes no warranty that this email is error or virus free.

  • Cannot find "Structure" menu under the Insert tab.  Need it to insert a header

    I just downloaded a trial version of DW CS6 and am following the on-line tutorial, but cannot find the "Structure" option under the "Insert" tab when creating an HTML document.  Where di it go?

    I think the confusion here is you appear to be following along some resource for DWCC while using DWCS6.
    There are many changes between DWCS6 and DWCC. Actually, there are quite a few changes between DWCS6 Disk version and DWCS6 Cloud version with even more between both of those and DWCC (and now DWCC 2014).
    With the speed that Adobe applications are changing with the Creative Cloud delivery system, you really must make sure you are using the correct resource version for your program version.

  • How to insert Tab Pages into a document

    I have a print job, where I need to insert tab pages into a document. Is there a tab template that I can insert into the Indesign document? If not, how can I create tab pages in Indesign?

    When I used to do tabs I would set up a page that was as wide as the tab sheet including the tab, then add text frames in each tab position.

  • Problem with loading tabs in JTabbedpane

    Hi,
    i am new to swing programming. I have a Jtabbedpane and i remove and add different tabs depending on the page i need to load.when i call the function which removes existing tabs and adds new one,the content of my frame changes but the new tabs gets loaded only on a "mouse click".Why is this so and could i make the tabs load automatically when i call the function?
    Any help would be appreciated..I have pasted the code below.
    void Settingfunc(){
    mainPanel.remove(tabbedPane);
    tabbedPane.removeAll();
    passwdadm();
    mainPanel.add(tabbedPane);
    void passwdadm(){
    panelfin = new JPanel();
    panelfin1.setLayout(new BorderLayout());
    JComponent panel1 = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    panel1.setLayout(gridbag);
    tabbedPane.addTab("Password", bot1, panelfin,
    "Does nothing");
    final JCheckBox chkbox1 = new JCheckBox("", true);
    chkbox1.setFont(new Font("Arial",Font.PLAIN,12));
    constraints.gridx=0;
    constraints.gridy=0;
    constraints.insets.top=20;
    gridbag.setConstraints(chkbox1,constraints);
    panel1.add(chkbox1);
    JLabel lnch=new JLabel("Require password to open program");
    lnch.setFont(new Font("Arial",Font.PLAIN,12));
    constraints.gridx=1;
    constraints.anchor=GridBagConstraints.WEST;
    constraints.gridy=0;
    gridbag.setConstraints(lnch,constraints);
    panel1.add(lnch);
    panelfin.add(panel1,BorderLayout.NORTH);
    }

    1) Post code using the "formatting tags" so your original formatting is retained.
    If you only want to replace the tabs in the tabbed pane then there is no need to use:
    mainPanel.remove(tabbedPane);  // not needed
    tabbedPane.removeAll();
    passwdadm();
    mainPanel.add(tabbedPane); // not neededHowever, if for some reason you feel you need to remove/add a component to a container then you need to revalidate the container so it can layout the components correctly. Something like:
    container.remove(...)
    container.add(....)
    container.revalidate();

  • Thumbnail view of  tabs in JTabbedPane

    Hi all,
    I am doing a desktop app . In my app i am using JTabbedPane . In order to view the contents of all tabs in one shot,i need to bring the JPanel in each tab into a single frame,that contains a scrollbar.i.e,something like a thumbnail view of all the tabs.Is it possible to do so? Since i have several components like button, textbox,images,etc in each tab,and have set the layout property of the panel to null,i cannot reduce the size of the panel to thumbnail size.I have set layout property of jpanel in each tab to null,because i have enabled dragging of objects like buttons,textarea,images,etc.Can anyone help me to sort out this problem.
    Thanks in advance
    Ravisenan

    Ok - you only gave iPhoto '11 - I assumed up to date
    Glad you found it anyway
    You are welcome
    LN

  • Inserting Tabs in the webtemplate

    Hi, People.
    I'm trying to insert the tab pages in to the webtemplate like shown inthe documetation example described following by this link
    http://help.sap.com/saphelp_nw04/helpdata/en/65/c54a7e1a1b584589d238ba188df053/content.htm
    but actually  I don't get the desired result, I thought may because of some wrong use of goto_tab function , but actually I have no idea where axactly . Can anyone axplain the meaning of all parameters in call
    SAPBWOpenURL(SAP_BW_URL_Get()'&item=TAB*&multi=X&hidden=X&cmd_1=item%3d'tabname+'*%26hidden%3d %26multi%3dX'); or may be there is some problem with this call?..

    Terence Devlin It was not my intention to step on your tone, Sorry for that.
    But.
    +Pathfinder is not a System Add-on. It's an application.+
    That is right it's an addition to the finder with different graphics and so it's not a modification to the standard window. What I like is a basic Finder window with just added tabs.
    +Sweeping generalisation there... and you've tried them all? Really?+
    Yes, I do think I tried them all and I still think they all miss the simplicity and elegance of the Finder windows. But if you know a good alternative (not pathfinder) I really would like that.
    +Pathfinder brings many very useful functions to the table - that's why one might consider it.+
    You are right. I do totally agree on that. But I rather work with the standard Finder window/info window , etc.
    +On the contrary it "do leaving the finder as it is" - it makes not a whit of a difference to the Finder, you can even run the two side by side if you want. Changes made in the filesystem with one will be instantly available in the other. Perhaps, in trying "all those system add-ons" you didn't try them very carefully.+
    That is exactly my point you end up using them side by side. Two different windows with things on different places. But I think on this point you really did not try to see what I was talking about.
    +Case in point. The Pathfinder window is highly customisable and all that functionality that you don't like can be hidden away.+
    Yes, But did you find a way to show all the other computers in the network in the side bar like the Finder (leopard) does?

Maybe you are looking for

  • My operating system is windows 2002, how can i provide and anti-virus protection, is it possible to get help for this obsolete system?y

    is it possible to get an anti-virus program for an obsolete operating system. Mine is windows xp 2002. i can't download a compatible service pack to compensate for the anti-virus program that i have or the one available for download provided by my in

  • Now what?

    Got my MBP about a month ago, and very glad that I did it (first time saw mac in front of me). Yesterday purchased LE7 and still waiting for it. I'm complete newbie here and my question is where do I start? Do I need anything else to buy, or install

  • HP Deskjet 3840 disappeared from my dropdown list.

    After installing the upgrade to Snow Leopard, My HP printer just disappeared as a selection from my dropdown list of printers, and I don't know how to get it back! Do I have to buy a new printer?

  • Disable OID user account

    I am new to OID, but very familar with Novell eDirectory and Microsoft Active Directory. Both Novell eDirectory and Microsoft Active Directory have the ability to disable login accounts so they can not be used for login (ie say when a user leaves you

  • ICloud email issue

    I recently changed my apple ID from a Hotmail.com email address to a gmail.com one. I'm trying to add my iCloud.com email address to my Airmail Mac App but the password is not recognised! I'm still receiving emails to my iCloud address and have tried