JTabbedPane and JInternalPanes

Hi,
I have a JFrame which contains a JDesktopPane. Inside the JDesktopPane, there are 4 JInternalPanes. What I want to do is that when any one of the JInternalPanes are maximized, I put them all into the JTabbedPane. How do I do that? I'm having trouble listening to the maximize event from the JInternalPane, to start with. Thanks.

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();
};

Similar Messages

  • 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();
    };

  • 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);

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

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

  • 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

  • A few questions regarding BorderLayout, JTabbedPane and JFrame.

    Hello,
    I'm after a little help. I want to know the following:
    1)
    How to you add a gap on the far left and far right so that the components at PAGE_START and PAGE_END when using BorderLayout have visible borders. I have tried the Constructor which lets you specific hGap and vGap but this does not work, I assume it is only when butting components together.
    2)
    When using JTabbedPanes with option
    setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT );is there a way to control painting of the Scroller which scrolls through the tabs? I am currently using a custom UI (subclassing BasicTabbedPaneUI) to paint my tabs however I can not work out how to paint the Scroller.
    3)
    How to I add a custom JFrame Border and remove the blue XP border? Do I need to setUndectored and add my own Icons? I want to achieve something along the lines of what you can see here
    https://substance.dev.java.net/images/screenshots/themes/skins/business1.png
    I will be using a custom L&F although not Substance and currently my L&F does not paint the border/Decorations on the Frame.
    Here is a picture of my app, outlining my problems.
    http://img91.imageshack.us/my.php?image=exampletz1.jpg
    A nudge in the right direction on any of these would be great.
    Thanks

    Hello,
    I'm after a little help. I want to know the
    following:
    1)
    How to you add a gap on the far left and far right so
    that the components at PAGE_START and PAGE_END when
    using BorderLayout have visible borders. I have
    tried the Constructor which lets you specific hGap
    and vGap but this does not work, I assume it is only
    when butting components together. agree vgap and hgap increase the vertical and horizontal distances between objects added to the panel that uses border layout.
    Why not do setBorder(BorderFactory.createEmptyBorder(.....) to do this for you?

  • JScrollPane for pane and JTabbedPane and Graphics

    Sort of have two topics with same problem.
    I have a set of Panels. I get a stream of jpegs which I have to decode to the fly.
    There are seperate video feeds in the stream and I have to read jpeg data to see which image goes where.
    I was trying to see if I could have a larger image in smaller area. this is why I tried to draw to panel inside a scrollpane.
    One: I tried to put a JPanel into JScrollPane and tried to draw an image to panel with Graphics g. No Scrollability and even when scroll bars are made to stay on permanently, they get overwritten.
    g=panel.getGraphics();
    if(isVisible()) g.drawImage(image,0,0,320,240,Color.BLUE,null);
    two: When putting the pane with the drawn images into toplevel pane into JtabbedPane. I can turn off the drawing of images with a check to isVisible(). When they are not in top level pane isVisible() does not work and the images get drawn over the other tabbed panes.
    BTW everything is swing. JPanel,JScrollPane,JTabbedPane.

    No Scrollability and even when scroll bars are made to stay on permanently,First of all the scrollbars will only appear when the preferred size of the panel is greater than the size of the scrollpane.
    A think a better design for updating the image is to extend JPanel and create a setImage method. The set image method would set the preferred size of the panel and then invoke repaint() on the panel. You would then also need to override the paintComponent(..) method to do the actual drawing of the image. Then when the image changes you just use the new setImage(..) method.

  • Help on JtabbedPane and JFrame

    Hi everyone, i am self studying java and I am following tutorials I got from Sun developer (the Divelog application). However, i can't figure out the following problem:
    1. The field DiveLog.dllframe is never read locally
    2. The field DiveLog.tabbedPane is never read locally
    3. The import java.awt is never used
    And here's my code...
    package divelog;
    import javax.swing.*;
    import java.awt.*;
    //import java.awt.event.*;
    //class defining application framework
    public class DiveLog
    private JFrame dlframe; //not assigned yet
    private final JTabbedPane tabbedPane; //not assigned yet
    public DiveLog()
    { // Opens constructor
    // Creates a frame object to add to
    // the application GUI components.
    dlframe = new JFrame("A Java Technology Dive Log");
    } // Closes main method
    } //Ends class DiveLog
    I hope guys that you can help me out... Thanks!

    when you declare the final variables, it should be initialized otherwise you will get error
    private final JTabbedPane tabbedPane; //not assigned yet should be
    private final JTabbedPane tabbedPane = new JTabbedPane()

  • JTabbedPane and focus

    I use a jTabbedPane in order to make un chain progression in data collections.
    I've searched in the functions and variables to know if it is possible to block
    the user on the last TabbedPane if he start using the last TabbedPane.
    I've placed previous and next buttons on each TabbedPane and i can disable these buttons,
    but i can't disable the tabbedPane above.
    I don't wish to use CardLayout for this (event if it is better for that), so if someone know how to
    solve this problem, thanks in advance.

    You can use JTabbedPane.setEnabledAt to set whether a particular tab is enabled or not. Just make a call to this with the code that enables/disables your previous and next buttons.
    Hope this helps.

  • JTabbedPane and Serialization

    Hi, I want to Serialize a JTabbedPane to a file but I am experiencing lots of problems :
    Firstly, I get an exception :
    java.io.NotSerializableException: javax.swing.plaf.basic.BasicTabbedPaneUI$MouseHandler
    I can override this in out custom plaf, but then this throws out pluggable look and feel. Is there any other way I can fix this ....
    Also I have had to change lots of code to get these to Serialize e.g cutomizing the BasicTabbedPaneUI and other classes to implement Serializable, and I get a bizarre problem where I write my Swing JxInternalFrame to disk, and then when I goto dispose of it, it throws a completely different Exception in firePropertyChanged within JTabbedPane.
    It tries to cast a JTabbedPane within the class BasicTabbedPaneUI$PropertyChangeHandler and the source is a Viewport... If I remove the Serialize to Disk code, then this does not occur!
    I am a little baffled why this happens ... can anyone help?

    My objective is to Serialize out the JxInternalFrame with all it's components to disk.
    We have an Application that Dynamically creates GUI interfaces using XML. Instead of creating the JxInternalFrame and all its components from the XML String, I thought it would be quicker to Serialize the Object to disk and re-read once the Frame once it had initialliy been built, for caching purposes.
    It takes about 4 seconds to build a 6MB JxInternalFrame with all its components (JTabbedPanes, JTextFields, JCombos etc....), and I want to minimise this to be almost instant ... i.e as if using JInternalFrame.setVisible( true or false ).
    I have not looked at XMLEncoder/Decoder yet, I will have a look and see if this will help or if this is fast enough.
    Bare in mind I could be opening a Screen many times, but do not want to initiate it again from raw XML AND I do not want to store Huge objects in memory.

Maybe you are looking for