AutoResize JTabbedPane

Hello
I have some problems using JTabbedPane. I insert a JTabbedPane into a JPanel with a BorderLayout manager. after this, i add to the JTabbedPane JPanels that contains JScrollpane with a JTextArea.
The problem comes when i enter text in one JTextArea, if i select an other tab, All the JTabbedPane is resized to display the JTextArea without vertical Scroll.
Where does the resize event come from ? Is there a solution to avoid this !
Thanks for helping me.
Eusebe

yes....
i did add this listener....but initially when i set the selectedTabIndex to 0
it wasn't firing the event ......
so i added
pane.setSelectedIndex(-1);
pane.setSelectedIndex(0);
and it started working fine.

Similar Messages

  • I want to  implement the Window autoresize in java swing application

    Hai...
    i want implement the window autoresize functionality in my java application. Same time i want to minimize and maximize my won window. and my java application develop one more frame at time disply in single window so i want disply the thaminal view formate in all frame
    Thanx to Advance.
    ARjun...

    ????????

  • How to Give MouseEvents for JTabbedPane??

    Hi All,
    I have some 10 tabs in a single JTabbedPane,So if i want to enlight the tab like when i just take my mouse cursor onto any tab it should have some effect/color changing,it should be higlighted in a different way compared to the other tabs.How can i implement this mechanism???
    Thanks in advance.
    regards,
    Viswanadh

    UIManager.put("TabbedPane.selected", Color.YELLOW );This will, however, affect all tabbed panes in your application.

  • Animated GIF in JTabbedPane - repaint madness!

    Loading and animated GIF into the icon for a JTabbedPAne just works, but it causes the paintComponent method on the main part of the panel to be called repeatedly. Anyway to distinguish between the two areas? The icon repaints automatically but I don't want to have to repaint the rest of the panel unnecessarily.

    I've run into the same problem simon, the only way I came over this was to do my own animation for the gif. Bit of a bother really. Anyone have any other solutions?

  • Mouse clicks not detected on JTabbedPane

    Hi all,
    I have a JPanel placed inside a JTabbedPane. I want to double-click on the JPanel and bring up a JDialog. This works fine if the JPanel is not in a JTabbedPane, but if it is on a JTabbedPane, then the mouse clicks are not detected. I'd greatly appreciate any help you can give me.

    Here is a sample program that seems to work:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class TestInternalFrame extends JFrame
         public TestInternalFrame()
              JDesktopPane desktop = new JDesktopPane();
              setContentPane( desktop );
              JInternalFrame internal = new JInternalFrame( "Internal Frame" );
              desktop.add( internal );
              internal.setLocation( 50, 50 );
              internal.setSize( 300, 300 );
              internal.setVisible( true );
              JTabbedPane tabbedPane = new JTabbedPane();
              internal.getContentPane().add(tabbedPane);
              tabbedPane.setPreferredSize( new Dimension(300, 200) );
              JPanel panel = new JPanel();
              tabbedPane.add( "Empty Panel", panel );
              panel.addMouseListener( new MouseAdapter()
                   public void mouseClicked(MouseEvent e)
                        System.out.println(e.getClickCount());
         public static void main(String args[])
    TestInternalFrame frame = new TestInternalFrame();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.setSize(400, 400);
    frame.setVisible(true);

  • How do I left justify the text in the tabs of a JTabbedPane.

    In 1.3.1 this used to work by supplying an HTML string with <div align="left"> but when I run with 1.4.1 this is now broken and I get center justification.
    Does anybody know a way to get the text in the tabs to be left justified.
    Thanks,
    Philip

    First, I found while using JTabbedPane that the "standard" behavior is to allow to a tab the exact space needed to display the tab text. Hence with this behavior, there is actualy no difference of "left" or "center" aligned text. So I assumed that you found a way or another to make your tabs wider than the "string width"...
    Here is a solution:
    You can override the TabbedPaneUI class and ajust the "layoutLabel()" method. Here is the code..
    //Your code using the tabbedPane
    JTabbedPane tp = new JTabbedPane();
    tp.setUI(new LeftTabbedPaneUI());
    //File containing the overrided TabbedPaneUI
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.text.View;
    class LeftTabbedPaneUI extends javax.swing.plaf.metal.MetalTabbedPaneUI {
            //I also overrided this function just to force tabs wider than
            //the displayed "String Width". I asume that you found another
            //way to do this so you can delete this function in your
            //implementation
         protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics){
              return 150;
        protected void layoutLabel(int tabPlacement,
                                   FontMetrics metrics, int tabIndex,
                                   String title, Icon icon,
                                   Rectangle tabRect, Rectangle iconRect,
                                   Rectangle textRect, boolean isSelected ) {
            textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
         View v = getTextViewForTab(tabIndex);
         if (v != null) {
             tabPane.putClientProperty("html", v);
         //This Line is added to avoid writing on tab border while aligned to left.
         //You can comment this line to test and or adjust the "5" pixel space
         Rectangle rec = new Rectangle(tabRect.x+5,tabRect.y,tabRect.width,tabRect.height);
            SwingUtilities.layoutCompoundLabel((JComponent) tabPane,
                                               metrics, title, icon,
                                               SwingUtilities.CENTER,
                                               SwingUtilities.LEFT,
                                               SwingUtilities.CENTER,
                                               SwingUtilities.TRAILING,
                                               rec,
                                               iconRect,
                                               textRect,
                                               textIconGap);
         tabPane.putClientProperty("html", null);
         int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
         int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
         iconRect.x += xNudge;
         iconRect.y += yNudge;
         textRect.x += xNudge;
         textRect.y += yNudge;
    }Here I overrided the "Metal" implementation of the tab but you must override the implementation of the used Look And Feel,
    ex. "com.sun.java.swing.plaf.window.WindowsTabbedPaneUI" for the windows LAF.

  • How can I change the font of the titles in a JTabbedPane

    Hi
    I use a JTabbedPane in a project and use windows LookAndFeel.
    I want to distinguish the selected Tab titels by changing the font of the title. Is there anybody who can help me. I can not find any component used as the title. They are only there when I create the tabs with.
    myTabbedPan.addTab("aTitle",aPanel);
    How TabbedPan use the string "aTitle" to create Tab "Buttons". Is there a component or... I can not get it
    Thanks
    nan2000

    Unfortunately, you have to sub-class the WindowsTabbedPaneUI to do that, and override the convenient methods.
    After that, you have to specify to the UIManager this new class it have to use to display the JTabbedPane components.
    Denis

  • Add button to JTabbedPane to add new tab

    Does anyone know how to add a JButton to a JTabbed pane (in the tab bar) so that it is always at the end of all the tabs and when it is clicked it will add a new tab into the tabbed pane.
    The functionallity I am looking for is the same as that provided by the button in the tab bar for Firefox and Internet Explorer.

    Along the line of what TBM was saying:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class NewTabDemo implements Runnable
      JTabbedPane tabs;
      ChangeListener listener;
      int numTabs;
      public static void main(String[] args)
        SwingUtilities.invokeLater(new NewTabDemo());
      public void run()
        listener = new ChangeListener()
          public void stateChanged(ChangeEvent e)
            addNewTab();
        tabs = new JTabbedPane();
        tabs.add(new JPanel(), "Tab " + String.valueOf(numTabs), numTabs++);
        tabs.add(new JPanel(), "+", numTabs++);
        tabs.addChangeListener(listener);
        JFrame frame = new JFrame(this.getClass().getName());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(tabs, BorderLayout.CENTER);
        frame.pack();
        frame.setSize(new Dimension(400,200));
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      private void addNewTab()
        int index = numTabs-1;
        if (tabs.getSelectedIndex() == index)
          tabs.add(new JPanel(), "Tab " + String.valueOf(index), index);
          tabs.removeChangeListener(listener);
          tabs.setSelectedIndex(index);
          tabs.addChangeListener(listener);
          numTabs++;
    }

  • Urgent - How to add a new control instead of tabs in JTabbedPane

    Hi,
    Please give me an idea or a sample program for how to add a new control
    in JTabbedpane instead of tabs that means overlay any Java controls or pane
    in the tabpane empty place next to tabs

    "Urgent" is not relevant to the question. Your question is no more important than anybody elses.
    My answer in this posting show a limited solution:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=636289
    Otherwise I suggest you try using a layered pane approach:
    http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

  • How to address a component in a background tab in a JTabbedPane

    Hello and greetings for everybody, this is my first post here. I have a question:
    I want to write a simple little chat program, which makes use of a JTabbedpane, and if the user gets a private message from another user, it would open a new tab with the given user's nick in the tab title, and would create a JTextArea on the opened tab and write the message to that specific JTextarea. My question: Is it possible to write on the JTextarea, while the given tab is in the background? How can I address that specific JTextarea on the specified tab?
    Thank you very much in advance for the answers, and I wis you all a nice day!

    // create a Map<String, JTextArea>
    public static void privMsg(String nick) {
            if (mainwindow.tabpane.indexOfTab(nick)==-1) {  // look for the nick in the map, not on the tabbedpane (if map.get(nick) != null
                javax.swing.JScrollPane panel=new javax.swing.JScrollPane();
                javax.swing.JTextArea msgBox=new javax.swing.JTextArea();
                msgBox.setEditable(false);
                msgBox.setAutoscrolls(true);
                msgBox.setLineWrap(true);
                panel.setViewportView(msgBox);
                mw.tabpane.addTab(nick,panel);
                mw.tabpane.setSelectedIndex(mw.tabpane.indexOfTab(nick));
                msgBox.append("Private conversation: "+nick+"\n");
                // add the nick and the msgBox to the map
            // if the nick already has been added to the map, (meaning there's already a tab open for that nick), then get that textpane and write to it. That's the basic idea behind MVC, which you'd do yourself a huge favor by reading into. You separate the display of the data from the data itself. That way when you update the data (Model), you don't have to deal with gui code (View). The actions the user takes are also separated into the Controller.

  • How can we prevent JTabbedPanes from transferring focus to components outside of the tabs during tab traversal?

    Hi,
    I noticed a strange focus traversal behavior of JTabbedPane.
    During tab traversal (when the user's intention is just to switch between tabs), the focus is transferred to a component outside of the tabs (if there is a component after/below the JTabbedPane component), if using Java 6. For example, if using the SSCCE below...
    import java.awt.BorderLayout;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class TabbedPaneTest extends JPanel {
        public TabbedPaneTest() {
            super(new BorderLayout());
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            add(new JScrollPane(panel));
        private JPanel buildPanelWithChildComponents() {
            JPanel panel = new JPanel();
            BoxLayout boxlayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
            panel.setLayout(boxlayout);
            panel.add(Box.createVerticalStrut(3));
            for (int i = 0; i < 4; i++) {
                panel.add(new JTextField(10));
                panel.add(Box.createVerticalStrut(3));
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneTest());
                    frame.pack();
                    frame.setVisible(true);
    ... Then we can replicate this behavior by following these steps:
    1) Run the program in Java 6; and then
    2) Click on a child component in any of the tabs; and then
    3) Click on any other tab (or use the mnemonic keys 'ALT + 1' to 'ALT + 4').
    At step 3 (upon selecting any other tab), the focus would go to the component below the JTabbedPane first (hence the printed message in the console), before actually going to the selected tab.
    This does not occur in Java 7, so I'm assuming it is a bug that is fixed. And I know that Oracle suggests that we should use Java 7 nowadays.
    The problem is: We need to stick to Java 6 for a certain application. So I'm looking for a way to fix this issue for all our JTabbedPane components while using Java 6.
    So, is there a way to prevent JTabbedPanes from passing the focus to components outside of the tabs during tab traversal (e.g. when users are just switching between tabs), in Java 6?
    Note: I've read the release notes between Java 6u45 to Java 7u15, but I was unable to find any changes related to the JTabbedPane component. So any pointers on this would be deeply appreciated.
    Regards,
    James

    Hi Kleopatra,
    Thanks for the reply.
    Please allow me to clarify first: Actually the problem is not that the child components (inside tabs) get focused before the selected tab. The problem is: the component outside of the tabs gets focused before the selected tab. For example, the JButton in the SSCCE posted above gets focused when users switch between tabs, despite the fact that the JButton is not a child component of the JTabbedPane.
    It is important for me to prevent this behavior because it causes a usability issue for forms with 'auto-scrolling' features.
    What I mean by 'auto-scrolling' here is: a feature where the form automatically scrolls down to show the current focused component (if the component is not already visible). This is a usability improvement for long forms with scroll bars (which saves the users' effort of manually scrolling down just to see the focused component).
    To see this feature in action, please run the SSCCE below, and keep pressing the 'Tab' key (the scroll pane will follow the focused component automatically):
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.JViewport;
    import javax.swing.SwingUtilities;
    public class TabbedPaneAutoScrollTest extends JPanel {
        private AutoScrollFocusHandler autoScrollFocusHandler;
        public TabbedPaneAutoScrollTest() {
            super(new BorderLayout());
            autoScrollFocusHandler = new AutoScrollFocusHandler();
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            button.addFocusListener(autoScrollFocusHandler);
            JScrollPane scrollPane = new JScrollPane(panel);
            add(scrollPane);
            autoScrollFocusHandler.setScrollPane(scrollPane);
        private JPanel buildPanelWithChildComponents(int numberOfChildComponents) {
            final JPanel panel = new JPanel(new GridBagLayout());
            final String labelPrefix = "Dummy Field ";
            final Insets labelInsets = new Insets(5, 5, 5, 5);
            final Insets textFieldInsets = new Insets(5, 0, 5, 0);
            final GridBagConstraints gridBagConstraints = new GridBagConstraints();
            JTextField textField;
            for (int i = 0; i < numberOfChildComponents; i++) {
                gridBagConstraints.insets = labelInsets;
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = i;
                panel.add(new JLabel(labelPrefix + (i + 1)), gridBagConstraints);
                gridBagConstraints.insets = textFieldInsets;
                gridBagConstraints.gridx = 2;
                textField = new JTextField(22);
                panel.add(textField, gridBagConstraints);
                textField.addFocusListener(autoScrollFocusHandler);
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6 with auto-scrolling");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneAutoScrollTest());
                    frame.setSize(400, 300);
                    frame.setVisible(true);
    * Crude but simple example for auto-scrolling to focused components.
    * Note: We don't actually use FocusListeners for this feature,
    *       but this is short enough to demonstrate how it behaves.
    class AutoScrollFocusHandler extends FocusAdapter {
        private JViewport viewport;
        private JComponent view;
        public void setScrollPane(JScrollPane scrollPane) {
            viewport = scrollPane.getViewport();
            view = (JComponent) viewport.getView();
        @Override
        public void focusGained(FocusEvent event) {
            Component component = (Component) event.getSource();
            view.scrollRectToVisible(SwingUtilities.convertRectangle(component.getParent(),
                    component.getBounds(), view));
    Now, while the focus is still within the tab contents, try to switch to any other tab (e.g. by clicking on the tab headers, or by using the mnemonic keys 'ALT + 1' to 'ALT + 4')...
    ... then you'll notice the following usability issue:
    1) JRE 1.6 causes the focus to transfer to the JButton (which is outside of the tabs entirely) first; then
    2) In response to the JButton gaining focus, the 'auto-scrolling' feature scrolls down to the bottom of the form, to show the JButton. At this point, the tab headers are hidden from view since there are many child components; then
    3) JRE 1.6 transfers the focus to the tab contents; then
    4) The 'auto-scrolling' feature scrolls up to the selected tab's contents, but the tab header itself is still hidden from view (as a side effect of the behavior above); then
    5) Users are forced to manually scroll up to see the tab headers whenever they are just switching between tabs.
    In short, the tab headers will be hidden when users switch tabs, due to the Java 6 behavior posted above.
    That is why it is important for me to prevent the behavior in my first post above (so that it won't cause usability issues when we apply the 'auto-scrolling' feature to our forms).
    Best Regards,
    James

  • JTabbedPane: Components before and after the tabs themselves.

    I want to make Google Chrome..!
    Well, really, I want to have GUI stuff up in the title pane. In particular, I want the tabs of a TabbedPane up there.
    I've concluded that the easiest way to accomplish this (hopefully in a somewhat LaF-neutral way) is to set the frame to be undecorated, and instead implement my own frame with handling and all. I'd set a JFrame undecorated, and put a JTabbedPane over the entire thing, sticking the application icon to the left of the tabs, and the minimize, maximize, close buttons to the far right of the tabs themselves.
    If anyone have any other suggestions to this initial problem, I would seriously appreciate to hear about them.
    But given the above solution: How would I go about getting a component to the left of the tabs, and some other components to the right of the tabs, of a JTabbedPane? A LaF-neutral solution would be very much appreciated - but I have faint hopes here, so pointers for how to accomplish this using LaF-tricks will be appreciated too.
    I've seen that laf-widget from kirill, https://laf-widget.dev.java.net/, does something like it (the magnifying-glass icon to the left of the tabs) for several LaFs. However, I must admit that I'm not yet well enough versed to understand how he does it - and also it seems like a somewhat complicated process, whereby one "physically" change the LaF in question (bytecode manipulates it), injecting the laf-widget stuff (and I still don't know how the JTabbedPane or TabbedPaneUI is modulated to inject that icon).
    Any help or pointers will be much appreciated!
    Thanks,
    Endre.

    Could you elaborate slightly on that? I don't get your "what's left" idea..?
    I think the JTabbedPane should have this functionality built-in. It is a truly obvious need, to the extent that it has had to be solved several times by others.
    From an answer to this problem on StackOverflow: The JideTabbedPane from the Jide open source parts have an setTabLeadingComponent. However, Jide doesn't manage to follow the active LaF (the installs its own UI delegate), so I don't instantly want to jump on it.

  • Adding a new Tab to an existing JTabbedPane not working

    Hello all,
    I am trying to add & display a new tab to an existing JTabbedPane when the user
    clicks on a button. For some reason the new tab, being added is not being displayed, and I don't know why. I have called invalidate(), validate() on the parent containers but haven't had any luck. I have also played around with SwingUtilities.invokeLater() and the Event thread, but have been unsuccessfull.
    Any help would be greatly appreciated.
          * This class is the parent that holds the internalFrame which is the
          * main parent for all subsequent containers
         public class QuoteRequestGUI implements QuoteRequestGUI_IF {
              protected JInternalFrame internalFrame_newQuoteRequest = new JInternalFrame("Quote Request");
              protected JTabbedPane tabbedPane = new JTabbedPane();
               * Create a new internal frame to which all the components of a new
               * QR will be added
              public JInternalFrame createNewQuoteRequestFrame() {
                   // Add a tabbed pane to the internal frame
                   internalFrame_newQuoteRequest.add(createQuoteRequestTabbedPane());
                   // .... Set various internalFrame properties
                   return internalFrame_newQuoteRequest;
              public JTabbedPane createQuoteRequestTabbedPane() {
                   // Create a new quote request details instance
                   QuoteRequestDetailsGUI_IF quoteRequestDetailsGUI =
                        new QuoteRequestDetailsGUI(quoteRequestStatusPassed);
                   // Create a new tab that will host all details of the quote request     
                   tabbedPane.addTab("Quote Request Details",
                             quoteRequestDetailsGUI.createQuoteRequestDetailsPanel());
                   return tabbedPane;
         public class QuoteRequestDetailsGUI extends QuoteRequestGUI implements QuoteRequestDetailsGUI_IF {
              private ProductDetailsGUI_IF productDetailsGUI = new ProductDetailsGUI();
               * Panel that will act as a container for both quote request and buyer
               * details
              public JPanel createQuoteRequestDetailsPanel() {
                   // Panel that will contain quoteRequest, buyer and buttons
                   JPanel panel_quoteRequestDetails = new JPanel();
                   // Create an intermediate panel so that components can be layed out properly
                   JPanel panel_quoteRequestIntermediatePanel = new JPanel();
                   // Set layout manager for panel
                   panel_quoteRequestIntermediatePanel.setLayout(
                        new BoxLayout(panel_quoteRequestIntermediatePanel,BoxLayout.PAGE_AXIS));
                   // Add the buttons
                   panel_quoteRequestIntermediatePanel.add(createQuoteRequestDetailsButtons());
                   // Add the intermediate panel to the main panel
                   panel_quoteRequestDetails.add(panel_quoteRequestIntermediatePanel);
                   return panel_quoteRequestDetails;
               * Panel that will hold all the buttons for the quote request details tabbed panel
              public JPanel createQuoteRequestDetailsButtons() {
                   // Panel to act as a container for the buttons
                   JPanel panel_quoteRequestDetailsButtons = new JPanel();
                   // Create, register action listeners and add buttons to the panel
                   JButton button_saveTabbedPane = new JButton("Save");
                   button_saveTabbedPane.addActionListener(new ActionListener() {
                        public void actionPerformed (ActionEvent actionEvent) {
                               saveTabbedPaneListener();
                   panel_quoteRequestDetailsButtons.add(button_saveTabbedPane);
                   return panel_quoteRequestDetailsButtons;
               * Display the save (product details) tabbed pane
               * @todo - Implement the save tabbed pane selected method
              public void saveTabbedPaneListener() {
                        log.info("tab count before added : " + tabbedPane.getTabCount());
                        // The product details of a particular quote request
                        tabbedPane.addTab("Product Details",
                                  productDetailsGUI.createProductDetailsPanel());
                        log.info("tab count after added : " + tabbedPane.getTabCount());
                        tabbedPane.invalidate();
                        tabbedPane.validate();
                        internalFrame_newQuoteRequest.revalidate();
         public class ProductDetailsGUI implements ProductDetailsGUI_IF {
               * Panel that will act as a container for both the product details (incl
               * table) and the buttons
              public JPanel createProductDetailsPanel() {
                   // Main product details panel
                   JPanel panel_productDetails = new JPanel();
                   // Add the scroll pane to the panel
                   panel_productDetails.add(new JButton("ok"));
                   // Add the buttons to the panel
                   // Add the scroll pane to the panel
                   panel_productDetails.add(new JButton("cancel"));
                   return panel_productDetails;
         }

    MS,
    Try copying one existing TAB and use that, this happens only when there is improper xml content. You can open the xml in the browser/visual studio for better clarity and then try making the changes. Doing IIS Reset will be required but in the meanwhile you
    can put the original RCDC which will work till the time you make any change in new TAB.
    Regards,
    Manuj Khurana

  • Creating a dropdown for the tabs that use JTabbedPane

    Hi all,
    I have an application that uses a JTabbedPane to create tabs. Currently it uses the default to scroll if there are more tabs than what can be fit on the screen. I would also like to provide a dropdown next to the scroll arrows so that the user can see all the tabs on a dropdown list and select one w/o having to scroll left and right. I've seen this done on the NetBeans IDE 4.1 and 5.0. Is this something I can leverage from the Swing API (using JDK 5), grab from some open-source library, or must code myself? Let me know how I can do this. Thanks in advance!
    -los

    Thanks for the reply!
    I understand what you are describing but am a bit puzzled on a couple of things (maybe because I just got into Swing).
    My biggest question is on how to place the combo box in the tabbed pane next to the scrolling arrows. I'm looking at the JTabbedPane Javadoc and I do not see a place where one can add other components such as this combo box (other than the tabs themselves).
    Another question is that the combo box will have a width the size of the longest text contained in the box. How do I remove this length and just show the dropdown arrow. When the user clicks this arrow, the combo box appears with the list of items, i.e. I want to mimic what the NetBeans IDE does.
    Thanks in advanced!
    -los

  • Resize JTable in JTabbedPane

    Given the FileTableDemo from the Java Foundation Class in a Nutshell book.(O'Reilly) Chapter 3 page 51 in my addition.
    I have modified the example to place the JTable in a JTabbedPane. Now when the window (JFrame) is resized by the user the JTable no longer resizes. How do I passing the "resizing" into the component (JTable) placed in the JTabbedPane?
    Here is the code: My deviation from the example is enclosed in "///////////KBS" and of course the line frame.getContentPane().add(myTP, "Center"); where "pane" has been replaced with "myTP"
    Thanks Brad
    import javax.swing.*;
    import javax.swing.table.*;
    import java.io.File;
    import java.util.Date;
    public class FileTableDemo
    public static void main(String[] args)
    // Figure out what directory to display
    File dir;
    if (args.length > 0)
    dir = new File(args[0]);
    else
    dir = new File(System.getProperty("user.home"));
    // Create a TableModel object to represent the contents of the directory
    FileTableModel model = new FileTableModel(dir);
    // Create a JTable and tell it to display our model
    JTable table = new JTable(model);
    JScrollPane pane = new JScrollPane(table);
    pane.setBorder(BorderFactory.createEmptyBorder(60,20,20,20));
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    JPanel myOne = new JPanel();
    JPanel myTwo = new JPanel();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS
    // Display it all in a scrolling window and make the window appear
    JFrame frame = new JFrame("FileTableDemo");
    frame.getContentPane().add(myTP, "Center");
    frame.setSize(600, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    // The methods in this class allow the JTable component to get
    // and display data about the files in a specified directory.
    // It represents a table with six columns: filename, size, modification date,
    // plus three columns for flags: direcotry, readable, writable
    class FileTableModel extends AbstractTableModel
    protected File dir;
    protected String[] filenames;
    protected String[] columnNames = new String[] {
    "name",
    "size",
    "last modified",
    "directory?",
    "readable?",
    "writable?"
    protected Class[] columnClasses = new Class[] {
    String.class,
    Long.class,
    Date.class,
    Boolean.class,
    Boolean.class,
    Boolean.class
    // This table model works for any one given directory
    public FileTableModel(File dir)
    this.dir = dir;
    this.filenames = dir.list();
    // These are easy methods
    public int getColumnCount()
    return 6;
    public int getRowCount()
    return filenames.length;
    // Information about each column
    public String getColumnName(int col)
    return columnNames[col];
    public Class getColumnClass(int col)
    return columnClasses[col];
    // The method that must actually return the value of each cell
    public Object getValueAt(int row, int col)
    File f = new File(dir, filenames[row]);
    switch(col)
    case 0: return filenames[row];
    case 1: return new Long(f.length());
    case 2: return new Date(f.lastModified());
    case 3: return f.isDirectory() ? Boolean.TRUE : Boolean.FALSE;
    case 4: return f.canRead() ? Boolean.TRUE : Boolean.FALSE;
    case 5: return f.canWrite() ? Boolean.TRUE : Boolean.FALSE;
    default: return null;
    }

    Well, I didn't find an answer but I did find a solution.
    The JPanel is the problem. I use it to help with layout which is not obvious in this example.
    As you can see in the code the JTable is placed in a JScrollPane which is place in a JPanel which is placed in a JTabbedPane.
    If I use Box instead of JPanel the JTable in the JScrollPane in the Box in the TabbedPane in the JFrame resizes correclty.
    So although JPanel is resizable with setSize it does not get resized when it's JFrame gets resized.
    I would still like to know why?
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    Box myOne = Box.createHorizontalBox();
    Box myTwo = Box.createHorizontalBox();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS

Maybe you are looking for

  • Transmit iPad to apple tv

    Can I transmit my iPad 2 display to apple tv?

  • Unable to edit My Settings

    My daughter put her name as an alia in my account and I am trying to change it to my name. When I try to delete the alia in My Settings the page closes without making the change. I am also unable to edit my own name but am able to make other changes.

  • ITunes purchased video has no audio or out of sync

    I purchased a TV series in the iTunes store and there is no audio on one of the TV episodes and it is out of sync in another episode by about 3 seconds. I have confirmed that it is the video files themselves that are to blame since iTunes and quickti

  • Iphone 5s won't turn on, battery is fine, and new charger

    I have bought a new charger for my iPhone 5s, its not charging nor will the apple logo or even battery logo with lightening bolt images pop up. Its been on the charger for days, no life. held home and power button, no life... held home button and plu

  • Index.cfm file

    Hi , I am new to coldfusion and i would like to have the following items clarified. 1) Why we need to have Index.cfm file 2) What is the diff between Application.cfm and Application.CFC I removed the index.cfm file from directory and accessed the app