JButton in jTabbedPane

Hi everyone,
I just wanna know if there is pain-less manner to add an exit button to the title of each tab in a jtabbedPane or not. Just like the tabs that are available in browsers with tab browsing feature, like Firefox an IE 6+, which contain a small button at the right side of each tab that closes the corresponding tab.
I think that if there isn't such feature included in jTabbedPane, one solution might be to use a set of jLables as tabs and use a panel with box layout as the panes, so that i could add some buttons to the labels. But I hope the jtabbedPane already gives us the ability to do so.
Please tell me if U have any other info,
thx in advance,
Capitan Haddock

I believe JDK6 allows you to add components to each tab.
Otherwise you can search the forum. There are examples of painting an "X" to represent a close icon.

Similar Messages

  • Organizing methods into classes...

    Does this sound acceptable/valid/good practice to other people? Note that this utility is still in the design phases and coding has not yet started.
    In a utility designed to transfer files to a storage server, I have four classes - one for pre-load processing and instantiation (sp?) the UI, one for data entry and processing, one for the user interface, and one for settings entry and processing. The data entry/processing class contains methods that validate the user inputs and the files being uploaded to make sure they meet the requirements I have set down. The settings entry/processing class has methods for reading in existing settings, writing changes to settings file(s), and validing the changes to settings. I'm planning on integrating exception handling and reporting into the utility so it will return (to the user as well as an error log file), the location (method of exception) and type of exception in a dialog.
    My problem comes when I look at the objects (especially in the UI class). The only object is the "main menu", which is a JFrame, some JPanels, JButtons, a JTabbedPane, and some JTextAreas with JLabels. But in the same class, I have methods that create JOptionPanes. And that's the only object I have. But shouldn't I have more objects than that? It seems akward to work with...but then again, I'm not that big on Java...I know how to work with it, but I prefer to work with C.

    Does this sound acceptable/valid/good practice to other people? Note that this utility is still in the design phases and coding has not yet started.
    In a utility designed to transfer files to a storage server, I have four classes - one for pre-load processing and instantiation (sp?) the UI, one for data entry and processing, one for the user interface, and one for settings entry and processing. The data entry/processing class contains methods that validate the user inputs and the files being uploaded to make sure they meet the requirements I have set down. The settings entry/processing class has methods for reading in existing settings, writing changes to settings file(s), and validing the changes to settings. I'm planning on integrating exception handling and reporting into the utility so it will return (to the user as well as an error log file), the location (method of exception) and type of exception in a dialog.
    My problem comes when I look at the objects (especially in the UI class). The only object is the "main menu", which is a JFrame, some JPanels, JButtons, a JTabbedPane, and some JTextAreas with JLabels. But in the same class, I have methods that create JOptionPanes. And that's the only object I have. But shouldn't I have more objects than that? It seems akward to work with...but then again, I'm not that big on Java...I know how to work with it, but I prefer to work with C.

  • JtabbedPane and Jbutton click help

    I have jPanel's added to the jTabbedPane.
    When the next button which is in the first jPanel is clicked I want to move to the next tab i.e the next jPanel.
    right now I have the following
    //ActionListener for jButton_Next Of NavigationButtons Panel
    newNavigationButtonsClass.jButton_Next.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    newNavigationButtonsClass.first_time_diaplay_buttons = false;
    newNavigationButtonsClass.jButton_Back.setEnabled(true);
    How can I change this to get it to work. Thanks.

    susmitha, Thanks for your help!
    does the JTabbedPane.setSelectedIndex(1);
    move to the next tab?
    I mean will the current pane that I can see is the 2nd JPanel(2nd tab)? or do I have to write something else so that I move to the 2nd Tab. I tried giving this but does not move to the next tab.
    //ActionListener for jButton_Next Of NavigationButtons Panel
    jButton_Next.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    first_time_display_buttons = false;
    getSelectedIndex();
    if((myMainFrame.selectedClientJTabbedPaneIndex == 0) &
    (myMainFrame.clientJTabbedPaneTabCount > 1)) {
    jButton_Back.setEnabled(true);
    newClientTabbedPaneClass.clientJTabbedPane.setSelectedIndex(1);
    protected void getSelectedIndex() {
    myMainFrame.selectedClientJTabbedPaneIndex = newClientTabbedPaneClass.clientJTabbedPane.getSelectedIndex();

  • 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++;
    }

  • 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

  • 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

  • How to adjust for different numbers of components on a JTabbedPane

    Hi,
    I have five panels on a JTabbedPane. On one, I have six components, with each being an array of five (in other words, I have six "columns" of five "rows" each). On another pane, I have only two components (not arrays). I understand that the JTabbedPane will be as large as the largest panel. In my case, the panel with two components is as large as the one with the arrays and the two components take up the entire panel. I have tried to adjust this by using the createGlue(), createHorizontalStrut(), and createVerticalStrut() methods, but it is somewhat "ugly." I am also using the Box layout. Is there a better way to do this? I have included some of my code for reference; (sorry for its length; I am including the code for only two of the five panels). Any assistance would be appreciated.
    TIA,
    Jeff
    Here is the code that creates the panel with the "columns" and "rows":
    public MailGen construct()
        //- create the controls for the emocPanel
        JLabel emocActionLabel = new JLabel( "ACTION" );
        emocActionLabel.setHorizontalAlignment( JLabel.CENTER );
        JLabel emocOrgIdLabel = new JLabel( "ORGANIZATION" );
        emocOrgIdLabel.setHorizontalAlignment( JLabel.CENTER );
        JLabel emocAircraftLabel = new JLabel( "AIRCRAFT" );
        emocAircraftLabel.setHorizontalAlignment( JLabel.CENTER );
        JLabel emocCatLabel = new JLabel( "CAT." );
        emocCatLabel.setHorizontalAlignment( JLabel.CENTER );
        JLabel emocSequenceLabel = new JLabel( "SEQ. # STARTS WITH" );
        emocSequenceLabel.setHorizontalAlignment( JLabel.CENTER );
        JLabel emocQuantityLabel = new JLabel( "QTY OF EMAILS" );
        emocQuantityLabel.setHorizontalAlignment( JLabel.CENTER );
        JComboBox emocActionComboBox;
        JTextField emocOrgTextField;
        JTextField emocAircraftTextField;
        JComboBox emocCategoriesComboBox;
        JTextField emocSequenceTextField;
        JTextField emocQuantityTextField;
        //- create the boxes that will contain the EMOC labels and controls
        Box northEmocBox = new Box( BoxLayout.X_AXIS );
        Box centerEmocBox = new Box( BoxLayout.X_AXIS );
        Box southEmocBox = new Box( BoxLayout.X_AXIS );
        //- add the EMOC labels to the northEmocBox
        //- HERE I AM USING STRUTS
        northEmocBox = Box.createHorizontalBox();
        northEmocBox.add( Box.createHorizontalStrut( 15 ) );
        northEmocBox.add( emocActionLabel );
        northEmocBox.add( Box.createHorizontalStrut( 40 ) );
        northEmocBox.add( Box.createVerticalStrut( 25 ) );
        northEmocBox.add( emocOrgIdLabel );
        northEmocBox.add( Box.createHorizontalStrut( 40 ) );
        northEmocBox.add( Box.createVerticalStrut( 25 ) );
        northEmocBox.add( emocAircraftLabel );
        northEmocBox.add( Box.createHorizontalStrut( 40 ) );
        northEmocBox.add( Box.createVerticalStrut( 25 ) );
        northEmocBox.add( emocCatLabel );
        northEmocBox.add( Box.createHorizontalStrut( 5 ) );
        northEmocBox.add( Box.createVerticalStrut( 25 ) );
        northEmocBox.add( emocSequenceLabel );
        northEmocBox.add( Box.createHorizontalStrut( 15 ) );
        northEmocBox.add( Box.createVerticalStrut( 25 ) );
        northEmocBox.add( emocQuantityLabel );
        northEmocBox.add( Box.createHorizontalStrut( 15 ) );
        JPanel mainEmocPanel = new JPanel();
        mainEmocPanel.setLayout( new BoxLayout( mainEmocPanel, BoxLayout.Y_AXIS ) );
        mainEmocPanel.add( northEmocBox );
        //- add the EMOC controls to the centerEmocBox
        Object[][] emocFieldTable = new Object[5][6];
        for ( int index = 0; index < 5; index++ )
          centerEmocBox = Box.createHorizontalBox();
          emocFieldTable[index][0] = new JComboBox( actions );
          ( ( JComboBox ) emocFieldTable[index][0] ).setBorder(
          BorderFactory.createLineBorder( Color.BLACK, 1 ) );
          emocFieldTable[index][1] = new JTextField( 3 );
          ( ( JTextField ) emocFieldTable[index][1] ).setBorder(
          BorderFactory.createLineBorder( Color.BLACK, 1 ) );
          emocFieldTable[index][2] = new JTextField( 3 );
          ( ( JTextField ) emocFieldTable[index][2] ).setBorder(
          BorderFactory.createLineBorder( Color.BLACK, 1 ) );
          emocFieldTable[index][3] = new JComboBox( categories );
          ( ( JComboBox ) emocFieldTable[index][3] ).setBorder(
          BorderFactory.createLineBorder( Color.BLACK, 1 ) );
          emocFieldTable[index][4] = new JTextField( 3 );
          ( ( JTextField ) emocFieldTable[index][4] ).setBorder(
          BorderFactory.createLineBorder( Color.BLACK, 1 ) );
          emocFieldTable[index][5] = new JTextField( 3 );
          ( ( JTextField ) emocFieldTable[index][5] ).setBorder(
          BorderFactory.createLineBorder( Color.BLACK, 1 ) );
          centerEmocBox.add( ( JComboBox )emocFieldTable[index][0] );
          centerEmocBox.add( ( JTextField )emocFieldTable[index][1] );
          centerEmocBox.add( ( JTextField )emocFieldTable[index][2] );
          centerEmocBox.add( ( JComboBox )emocFieldTable[index][3] );
          centerEmocBox.add( ( JTextField )emocFieldTable[index][4] );
          centerEmocBox.add( ( JTextField )emocFieldTable[index][5] );
          mainEmocPanel.add( centerEmocBox );
        //- create the SEND and CANCEL buttons
        JButton emocSendButton = new JButton( "SEND EMAIL" );
        emocSendButton.setBackground( Color.white );
        emocSendButton.setBorder( raisedBevel );
        JButton emocCancelButton = new JButton( "CANCEL" );
        emocCancelButton.setBackground( Color.white );
        emocCancelButton.setBorder( raisedBevel );
        //- add the buttons to the southEmocBox
        southEmocBox = Box.createHorizontalBox();
        southEmocBox.add( emocSendButton );
        southEmocBox.add( emocCancelButton );
        mainEmocPanel.add( southEmocBox );Here is the code that creates the panel with only two components:
    //- create the controls for preguardPanel
        JLabel preguardActionLabel = new JLabel( "SELECT ACTION" );
        preguardActionLabel.setHorizontalAlignment( JLabel.CENTER );
        preguardActionLabel.setPreferredSize( new Dimension( 100, 10 ) );
        JComboBox preguardActionComboBox = new JComboBox( actions );
        preguardActionComboBox.setBorder( BorderFactory.createLineBorder(
            Color.BLACK, 1 ) );
        preguardActionComboBox.setPreferredSize( new Dimension( 30, 10 ) );
        //- create the SEND and CANCEL buttons
        JButton preguardSendButton = new JButton( "SEND ACTION" );
        preguardSendButton.setBackground( Color.white );
        preguardSendButton.setBorder( raisedBevel );
        JButton preguardCancelButton = new JButton( "CANCEL" );
        preguardCancelButton.setBackground( Color.white );
        preguardCancelButton.setBorder( raisedBevel );
        //- create the boxes that will contain the preguard label and control
        Box northPreguardBox = new Box( BoxLayout.X_AXIS );
        Box centerPreguardBox = new Box( BoxLayout.X_AXIS );
        Box southPreguardBox = new Box( BoxLayout.X_AXIS );
        //- add the preguard label to the northPreguardBox
        northPreguardBox = Box.createHorizontalBox();
        northPreguardBox.add( Box.createGlue() );
        //northPreguardBox.add( Box.createGlue() );
        northPreguardBox.add( preguardActionLabel );
        //northPreguardBox.add( Box.createGlue() );
        northPreguardBox.add( Box.createGlue() );
        JPanel mainPreguardPanel = new JPanel();
        mainPreguardPanel.setLayout( new BoxLayout(
            mainPreguardPanel, BoxLayout.Y_AXIS ) );
        mainPreguardPanel.add( northPreguardBox );
        //- add the preguard control to the centerPreguardBox
        //- HERE IS THE "GLUE" I AM USING
        centerPreguardBox = Box.createHorizontalBox();
        centerPreguardBox.add( Box.createGlue() );
        centerPreguardBox.add( Box.createGlue() );
        centerPreguardBox.add( Box.createGlue() );
        centerPreguardBox.add( Box.createGlue() );
        centerPreguardBox.add( preguardActionComboBox );
        centerPreguardBox.add( Box.createGlue() );
        centerPreguardBox.add( Box.createGlue() );
        centerPreguardBox.add( Box.createGlue() );
        centerPreguardBox.add( Box.createGlue() );
        mainPreguardPanel.add( centerPreguardBox );
        //- add the buttons to the southPreguardBox
        southPreguardBox = Box.createHorizontalBox();
        southPreguardBox.add( Box.createHorizontalStrut( 10 ) );
        southPreguardBox.add( preguardSendButton );
        southPreguardBox.add( preguardCancelButton );
        mainPreguardPanel.add( southPreguardBox );Here, I am adding the panels to the JTabbedPane:
    //- add the panels to the tabbed pane
       JTabbedPane pane = new JTabbedPane();
       pane.add( "EMOC", mainEmocPanel );
       pane.add( "PREGUARD", mainPreguardPanel );
    }

    This seems to be a commercial product. For the best chance at finding a solution I would suggest posting in the forum for HP Business Support!
    You can find the Commercial Designjet board here:
    http://h30499.www3.hp.com/t5/Printers-Designjet-Large-Format/bd-p/bsc-414
    Best of Luck!
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • How to use put Obsever Patterns in JTabbedPane layout

    Hi, I am trying to put Observer Patterns in a JTabbedPane layout so that my program can pass event data to other class. But I don't know how I can accomplish this. Could someone help me?
    Thanks,
    Joanna
    import javax.swing.*;
    public class Restaurant {
         public static void main(String[] args) {
              JFrame frame = new JFrame("168 Restaurant");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JTabbedPane tp = new JTabbedPane();
              pizzaPanel pPanel = new pizzaPanel(); // create pizzaPanel class
              tp.addTab("Order", pPanel);
              double total; String result;
              total = pPanel.getTotal();                       //get total price and order from pizzaPanel class
              result = pPanel.getPizza();
              pricePanel price = new pricePanel(total, result);       //pass to pricePanel class
              tp.addTab("Payment", price);
              frame.getContentPane().add(tp);
              frame.pack();
              frame.setVisible(true);
    //pizzaPanel class
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class pizzaPanel extends JPanel {
         public double total = 0;
         public String order = " ";
         private JPanel titlePanel = new JPanel();
         private JPanel gridPanel = new JPanel();
         private JRadioButton cb1, cb2;
         private JButton submit;
         public pizzaPanel () {
              titlePanel.setPreferredSize(new Dimension(100, 30));
              titlePanel.setLayout(new FlowLayout());
              JLabel label = new JLabel("Please order your food");
              titlePanel.add(label);
              gridPanel.setLayout (new GridLayout(1, 4));
              JLabel b1 = new JLabel("Premium Goats' Cheese $5.00");
              cb1 = new JRadioButton ("1");cb2 = new JRadioButton ("2");
              submit = new JButton("Submit");
              submit.setPreferredSize(new Dimension(50, 20));
              ButtonListener listener = new ButtonListener();
              submit.addActionListener(listener);
              ButtonGroup bg1 = new ButtonGroup ();
              bg1.add(cb1);bg1.add(cb2);
              gridPanel.add(b1);gridPanel.add(cb1);gridPanel.add(cb2);
              setPreferredSize(new Dimension (200, 200));
              setLayout(new BorderLayout());
              add(titlePanel, BorderLayout.NORTH);
              add(gridPanel, BorderLayout.CENTER);
              add(submit, BorderLayout.SOUTH);
         public class ButtonListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
              if (cb1.isSelected()) {                                   
                   total += 5;                         //total is obtained here
                   order += "Goats' Cheese" + " \n";               //order is obtained here
             else if (cb2.isSelected()) {
                   total += 10;                         //total is obtained here
                   order += "Goats' Cheese" + " \n";                //order is obtained here
            if (e.getSource() == submit)
                JOptionPane.showMessageDialog (null, order  + "\t = $" + total + "\n Please click Payment tab");
         public double getTotal(){               //try to pass the total out
              return total;               
         public String getPizza(){                  //try to pass the order out
              return order;
    //pricePanel class
    import java.awt.*;
    import javax.swing.*;
    public class pricePanel extends JPanel {
         public pricePanel (double total, String order) {           //total and order are passed in
              setPreferredSize(new Dimension (300, 200));
              setBackground (Color.green);
              setLayout(new FlowLayout());
              JLabel l1 = new JLabel ("Please pay the amount: ");     
              JLabel l2 = new JLabel (order + ": \t $" + total);   //total & order don't hold values obtained from
                                        //pircePanel class.
              add(l1);add(l2);
    }

    Please don't double post. This is quite rude. I've a mind to delete my recent post in your other thread.

  • Unicode font usage with jTabbedPane

    Hey there
    I faced a problem when I use Unicode characters on JTabbedPane
    the font is amharic power geez unicode1 and it works fine with jLabel and partially with jButtons ( except trying to set text at run time )
    The problem with jTabbedpane is that when I change its tab title property the other tabs disappear ( am using netbeans 5.5 )

    To me, it looks as if your problem is that you're only calling setFont on "this".
    That's only going to set it for the top level frame, and doesn't always do it for every individual component. The easy way to get around this is to go berserk with the setFont call. Set it on anything (heck, set it on your dog if it makes you feel any better)! ;D
    The slightly harder but smarter way to do this is to write a recursive function that drills down your component list.
    public void setFontRecursively(Font myFont, Component comp) {
       comp.setFont(myFont);
       if (comp instanceof Container) {
          Component[] childComps = ((Container)comp).getComponents();
          if (childComps != null) {
             for (int i=0; i < childComps.length; i++) {
                setFontRecursively(myFont, childComps);
    That should basically cover anything bar popup menus and drop-down submenus. You have to recall this as they appear, or they don't get the font straight off.
    Hope that helps!
    Martin Hughes

  • Keyboard shortcuts in JTabbedPane don't work in BorderLayout

    I'm mystified by a problem that doesn't seem to make any sense. I have a JTabbedPane with mnemonics, that used to work well before. But since I've shuffled components around a bit and put the JTabbedPane in the BorderLayout.CENTER of a JPanel, the keyboard shortcuts no longer work.
    The appropriate letters are underlined, but the Alt+letter sequence no longer switched tabs. Other components (JButtons) with keyboard shortcuts in the same JPanel, but in the BorderLayout.SOUTH or elsewhere, work as expected.
    It sounds like a bug to me, but is there perhaps a workaround?
    Thanks,
    - Peter

    I keep replying to my own posts...
    I figured out that the tabs start working once a component in them (say, a JTextField) receives keyboard focus. It does sound a bit suspicious to me, but I can live with it.
    Unfortunately, setting the focus programmatically doesn't seem to work: requestFocus() or requestFocusInWindow() on the first JTestBox simply don't work.
    - Peter

  • Exception with JTabbedPane

    In my project, I build a dialog box. I build a JTabbedPane within. Each tab is a panel with JChecxBox. When I add my first panel using the method addTab() no problem, with my second panel still no problem. When I try adding a third, an exception occurs: java.lang.ArrayIndexOutOfBoundsException: 2>1
    I have also used the method printStackTrace to know what's going on:
    java.lang.ArrayIndexOutOfBoundsException: 2 > 1
         at java.util.Vector.insertElementAt(Vector.java:551)
         at javax.swing.JTabbedPane.insertTab(JTabbedPane.java:441)
         at javax.swing.JTabbedPane.addTab(JTabbedPane.java:512)
         at myprojects.hopital.Cl�sComp.<init>(Cl�sComp.java:113)
         at myprojects.hopital.Hopital$1$MenuAction.actionPerformed(Hopital.java:72)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
         at javax.swing.AbstractButton.doClick(AbstractButton.java:279)
         at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:886)
         at java.awt.Component.processMouseEvent(Component.java:3717)
         at java.awt.Component.processEvent(Component.java:3546)
         at java.awt.Container.processEvent(Container.java:1164)
         at java.awt.Component.dispatchEventImpl(Component.java:2595)
         at java.awt.Container.dispatchEventImpl(Container.java:1213)
         at java.awt.Component.dispatchEvent(Component.java:2499)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
         at java.awt.Container.dispatchEventImpl(Container.java:1200)
         at java.awt.Window.dispatchEventImpl(Window.java:912)
         at java.awt.Component.dispatchEvent(Component.java:2499)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
         at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
    It seems that addTab call insertTab calling himself insertElementAt which throw this exception? I don't understand what's going on. Here my code for my DialogBox:
    package myprojects.hopital;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.util.*;
    //import java.lang.*;
    public class Cl�sComp extends JDialog {
         Comparateur[] cl�s;
         int nbCl�s;
         boolean ok;
         JCheckBox jcbAdd;
         JCheckBox jcbMoy;
         JCheckBox jcbM�d;
         JCheckBox jcbEct;
         JCheckBox jcbSamj;
         JCheckBox jcbAll;
         JCheckBox jcbProv;
         JCheckBox jcbTadm;
         JCheckBox jcbTpat;
         JCheckBox jcbAmoy;
         JCheckBox jcbAmed;
         JCheckBox jcbAect;
         JCheckBox jcbVobsinf;
         public Cl�sComp(){
              super((JFrame)null,"Choix des cl�s de comparaisons",true);
              Container contentPane=getContentPane();
              //setLayout(new GridBagLayout());
              nbCl�s=0;
              cl�s=new Comparateur[10];
              class ButtonAction implements ActionListener
                   public void actionPerformed(ActionEvent e) {
                        String commande;
                        commande=e.getActionCommand();
                        if (commande.compareTo("Cancel")==0){
                             hide();
                        if (commande.compareTo("OK")==0){
                             if (jcbAdd.isSelected()) {
                                  Comparateur c=new Comparateur(1);
                                  addCl�(c);
                                  ok=true;
                             if (jcbMoy.isSelected()) {
                                  Comparateur c=new CompMoy(0);
                                  addCl�(c);
                                  ok=true;
                             if (jcbM�d.isSelected()) {
                                  Comparateur c=new CompMed(0);
                                  addCl�(c);
                                  ok=true;
                             if (jcbEct.isSelected()) {
                                  Comparateur c=new CompET(0);
                                  addCl�(c);
                                  ok=true;
                             if (jcbSamj.isSelected()) {
                                  Comparateur c=new CompSAMJ(0);
                                  addCl�(c);
                                  ok=true;
                             hide();
              JTabbedPane jtpMisc=new JTabbedPane();
              JPanel jpCheckBox=new JPanel(new GridLayout(2,2));
              jcbAdd=new JCheckBox("Nombre");
              jcbMoy=new JCheckBox("Moyenne");
              jcbM�d=new JCheckBox("M�diane");
              jcbEct=new JCheckBox("Ecart-type");
              jcbSamj=new JCheckBox("Sapi activit� moyenne");
              jcbAll=new JCheckBox("Tout");
              jcbProv=new JCheckBox("Provenance");
              jcbTadm=new JCheckBox("Type d'admission");
              jcbTpat=new JCheckBox("Type de pathologie");
              jcbAmoy=new JCheckBox("Moyenne");
              jcbAmed=new JCheckBox("M�diane");
              jcbAect=new JCheckBox("Ecart-Type");
              jpCheckBox.add(jcbAdd);
              jpCheckBox.add(jcbMoy);
              jpCheckBox.add(jcbM�d);
              jpCheckBox.add(jcbEct);
              jpCheckBox.add(jcbSamj);
              jtpMisc.addTab("Divers",null,jpCheckBox,"C'est compl�tement foireux");
              jtpMisc.setSelectedIndex(0);
              JPanel jpParamPhys=new JPanel();
              jcbVobsinf=new JCheckBox("Valeur obs. inf.");
              jpParamPhys.add(jcbVobsinf);
              jtpMisc.addTab("Param�tres physiologiques",jpParamPhys);
              JPanel jpActivit�s=new JPanel();
              jpActivit�s.add(jcbProv);
              JPanel jpSapiSev=new JPanel();
              jpSapiSev.add(jcbTpat);
              JPanel jpSapiAct=new JPanel();
              jpSapiAct.add(jcbTadm);
    try{     jtpMisc.addTab("Activit�s",jpParamPhys);
         //     jtpMisc.addTab("SAPI-SEVERITE",jpParamPhys);
         //     jtpMisc.addTab("SAPI-ACTIVITE",jpParamPhys);
         catch(Exception e){
              System.out.println(e.toString());
              System.out.println(e.getMessage());
              System.out.println(e.getLocalizedMessage());
              try{e.printStackTrace(new PrintStream(new FileOutputStream("c:\\Beno�t\\error.txt")));}
              catch(Exception exc){System.out.println("Encore une exception, putain");}
              ButtonAction bAction=new ButtonAction();
              JPanel jpButton=new JPanel(new GridLayout(1,2));
              JButton jbOk=new JButton("OK");
              JButton jbCancel=new JButton("Cancel");
              jpButton.add(jbOk);
              jpButton.add(jbCancel);
              jbCancel.addActionListener(bAction);
              jbOk.addActionListener(bAction);
              contentPane.add(jpButton,BorderLayout.SOUTH);
              contentPane.add(jtpMisc,BorderLayout.CENTER);
         //     contentPane.add(jpCheckBox,BorderLayout.CENTER);
              setSize(500,400);
              setLocation(200,150);
         public Comparateur getCl�(int index){
              return cl�s[index];
         public boolean ok(){
              return ok;
         public int getNbCl�s(){
              return nbCl�s;
         public void addCl�(Comparateur c){
              nbCl�s++;
              cl�s[nbCl�s-1]=c;
    }

    Conceptually wrong.
    Hints: every tab in a JTabbedPane is a JPanel in fact.

  • JTabbedPane, JPane PROBLEM

    Hi!, I have a several problem with JApplet, this is the code:
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.io.*;
    import java.awt.*;
    public class NuevoApplet extends JApplet{
    JMenuBar menuBar;
    JMenu menuArchivo, submenu;
    JMenuItem menuNuevo;
    JTabbedPane Tabbed1 = new JTabbedPane();
    JPanel Panel = new JPanel();
    class EventHandler implements ActionListener
              public void actionPerformed(ActionEvent e)
                   //Si se elige salir en el menu
                   if (e.getSource() == menuNuevo)
                        CreaTab();
    ActionListener eventHandler = new EventHandler();
    public void start(){}
    public void init () {
    try {
    UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
    } catch (Exception e) { }
    Panel.setBorder(BorderFactory.createEtchedBorder());
    Panel.setLayout(new java.awt.BorderLayout());
    this.Panel.updateUI();
    this.setContentPane(this.Panel);
    this.CreaMenus();
    this.getContentPane().add(this.Tabbed1,java.awt.BorderLayout.CENTER);
    initConnections();
    private void CreaMenus(){
    //Creamos la barra de men�s
    menuBar = new JMenuBar();
    this.setJMenuBar(menuBar);
    //Creamos el men� de Archivo
    menuArchivo = new JMenu("Archivo");
    menuBar.add(menuArchivo);
    //Creamos los elementos del men� archivo
    menuNuevo = new JMenuItem("Abrir Archivo *.hex");
    menuArchivo.add(menuNuevo);     
    public void initConnections()
    //se suscriben todas las componentes que quieren escuchar los eventos
         menuNuevo.addActionListener(eventHandler);
    public void CreaTab(){
    JPanel a = new JPanel();
    Entorno1 b = new Entorno1();
    a.add(new JButton("BOTON1"),java.awt.BorderLayout.CENTER);
    a.add(new JButton("BOTON2"),java.awt.BorderLayout.EAST);
    this.Tabbed1.addTab("Primera Pesta�a", b); --> PROBLEM, not insert the JPanel b extends Entorno1
         b.repaint();
         Tabbed1.invalidate();
    Tabbed1.getParent().invalidate();
    Tabbed1.validate();
    Tabbed1.repaint();
         this.Tabbed1.updateUI();
         /*this.Tabbed1.validate();
         this.Tabbed1.updateUI();
         this.Tabbed1.revalidate();*/
    public class Entorno1 extends JPanel{
    public void Entorno1(){
         setLayout(new BorderLayout());
         Border raisedBevel = BorderFactory.createRaisedBevelBorder();
    Border loweredBevel = BorderFactory.createLoweredBevelBorder();
    Border compound = BorderFactory.createCompoundBorder
    (raisedBevel, loweredBevel);
    this.setBorder(compound);
    this.add(new JButton("Boton1"),java.awt.BorderLayout.CENTER);
    this.add(new JButton("Boton2"),java.awt.BorderLayout.EAST);
    this.updateUI();
    this.setVisible(true);
    this.revalidate();
    this.repaint();
    } //Fin de la clase Applet16F84
    When I use b extends Entorno1 and I insert as JPanel of JTabbedPane, not show it.
    this.Tabbed1.addTab("Primera Pesta�a", b);
    But this yes show it:
    this.Tabbed1.addTab("Primera Pesta�a", a);
    Why ? ..
    Thanks !

    Your constructor is actually a method and not a constructor.
    Therefore calling new Entorno1() returns you a blank panel.
    change this
    public void Entorno1(){
    ...to this.
    public Entorno1(){that should do it..
    nes

  • Add tool tip to left right button in JTabbedPane??

    Hi,
    I am using a tabbed pane with follwong setting.
    tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    So when the no of tab is more a left right button appears.
    I want to add tool tip to these button
    How do i get the instance of these buttons
    thnx
    Neel

    try this for east/west, similar for north/south
    (hopefully there's an easier way)
    import java.awt.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setLocation(300,200);
        setSize(150,100);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JTabbedPane tp = new JTabbedPane();
        tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        tp.setUI(new MyUI());
        for(int x = 0; x < 12; x++)
          JPanel p = new JPanel();
          p.add(new JLabel(""+x));
          tp.addTab(""+(char)(x+65),p);
        getContentPane().add(tp);
      class MyUI extends javax.swing.plaf.metal.MetalTabbedPaneUI
        protected JButton createScrollButton(int direction)
          if (direction != SOUTH && direction != NORTH && direction != EAST && direction != WEST)
              throw new IllegalArgumentException("Direction must be one of: SOUTH, NORTH, EAST or WEST");
          return new ScrollableTabButton(direction);
        private class ScrollableTabButton extends javax.swing.plaf.basic.BasicArrowButton implements javax.swing.plaf.UIResource,SwingConstants
          public ScrollableTabButton(int direction)
            super(direction, UIManager.getColor("TabbedPane.selected"),
                             UIManager.getColor("TabbedPane.shadow"),
                             UIManager.getColor("TabbedPane.darkShadow"),
                             UIManager.getColor("TabbedPane.highlight"));
            if(direction == WEST) setToolTipText("<<<<<");
            else if(direction == EAST) setToolTipText(">>>>>");
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • JTabbedPane with JSplitPane - HELP !!!

    What am I missing??? I have a JSplitPane in a TabbedPane. The topComponent contains a JComboBox with Key values, the Bottom Component will display details based on the key value passed. The bottomComponent has 2 constructors: one default and one accepting an Argument. The default constructor instantiate the class that would represent the data and formats the bottomComponent. The second constructor retrieves the data from the Oracle database and formats the BottomComponent using the same method. I put System.out messages and the values are showing using the Second constructor. Your help is greatly appreciated.

    This is the complete set of code. I hope you can follow the logic. I tried your last suggestion without any success. Maybe by reviewing the code you can see a problem. I appreciate your help greatly. Thanks.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Management extends JPanel implements ChangeListener{
    //private JFrame dlframe;
    private JTabbedPane propPane;
    public Management(){
    propPane = new JTabbedPane(SwingConstants.TOP);
    propPane.setSize(795, 550);
    propPane.addChangeListener(this);
    populateTabbedPane();
    // getContentPane().add(propPane);
    add(propPane);
    } // end of constructor
    // create tabs with titles
    private void populateTabbedPane(){
         propPane.addTab("Management", null, new Mgmt(), "Management");
         propPane.addTab("Management Contact", null,
    new Management_Contact(), "Management Contact");
    } // end of populateTabbedPane
    public void stateChanged(ChangeEvent e){
         System.out.println("\n\n ****** Management.java " + propPane.getSelectedIndex() + " " + propPane.getTabPlacement());
    public static void main(String[] args){
    Home dl = new Home();
    dl.pack();
    dl.setSize(800, 620);
    dl.setBackground(Color.white);
    dl.setVisible(true);
    } // end of class Management
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Management_Contact extends JPanel {
         Mgmt_Class mgmt = null;
         Mgmt_Contact mgmtContact = null;
         public Management_Contact() {
              JSplitPane split = new JSplitPane();
              split.setOrientation(JSplitPane.VERTICAL_SPLIT);
              Mgmt_Header hdr = new Mgmt_Header();
              split.setTopComponent(hdr);
              Mgmt_Contact mgmtContact = new Mgmt_Contact();
              JScrollPane scrollPane = new JScrollPane(mgmtContact,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
              JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              scrollPane.setPreferredSize(new Dimension(650,300));
              split.setBottomComponent(scrollPane);
              add(split);
    } // end of Management class
    import java.util.Vector;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Mgmt_Header extends JPanel implements ActionListener{
    private JComboBox cmbMgmt;
    private JTextField txtMgmtCode;
    private JTextField txtMgmtAddr1;
    private JTextField txtMgmtAddr2;
    private JTextField txtMgmtCity;
    private JButton sel;
    private JLabel lblBlk;
    private JPanel pWork;
    private Box vertBox;     
    private Box topBox;     
    private Box midBox;     
    private Box botBox;     
    JToolTip toolTip = null;
    private Mgmt_Class mClass = null;
    private Mgmt_Contact cnt = null;
    Vector mgmtVct = null;
    public Mgmt_Header(){
         vertBox = Box.createVerticalBox();
         topBox = Box.createHorizontalBox();
         midBox = Box.createHorizontalBox();
         botBox = Box.createHorizontalBox();
    mClass = new Mgmt_Class();
    mgmtVct = new Vector();
         cmbMgmt = new JComboBox();
         cmbMgmt.addItem(" ");
         mgmtVct = mClass.bldMgmtHeader();
         for (int x1=0; x1<mgmtVct.size() ;x1++ )
         mClass = (Mgmt_Class)mgmtVct.get(x1);
         cmbMgmt.addItem(mClass.getManagementName());
    System.out.println("MgmtHeader " + mgmtVct.size() + " " + cmbMgmt.getItemCount());
         cmbMgmt.setEditable(false);
         cmbMgmt.setBackground(Color.white);
         cmbMgmt.setName("cmbMgmt");
         cmbMgmt.setPreferredSize(new Dimension(250,27));
         cmbMgmt.setFont(new Font("Times-Roman",Font.PLAIN,12));
         cmbMgmt.addActionListener(this);
         pWork = new JPanel();
         pWork.setLayout(new FlowLayout(FlowLayout.CENTER));
         pWork.setBorder(BorderFactory.createTitledBorder(" Select Management Name "));
         pWork.add(new JLabel("Name: "));
         pWork.add(cmbMgmt);
         topBox.add(pWork);
         txtMgmtAddr1 = new JTextField("Address line 1",15);
         txtMgmtAddr1.setEditable(false);
         txtMgmtAddr2 = new JTextField("Address line 2",15);
         txtMgmtAddr2.setEditable(false);
         txtMgmtCity = new JTextField("City",15);
         txtMgmtCity.setEditable(false);
         midBox.add(midBox.createVerticalStrut(10));
         botBox.add(new JLabel("Address:"));
         botBox.add(topBox.createHorizontalStrut(15));
         botBox.add(txtMgmtAddr1);
         botBox.add(topBox.createHorizontalStrut(15));
         botBox.add(txtMgmtAddr2);
         botBox.add(topBox.createHorizontalStrut(15));
         botBox.add(txtMgmtCity);
         vertBox.add(topBox);
         vertBox.add(midBox);
         vertBox.add(botBox);
         add(vertBox);
    } // end of constructor
         public void actionPerformed(ActionEvent evt){
         if (evt.getSource() instanceof JComboBox){
         if (((JComboBox)evt.getSource()).getName() == "cmbMgmt"){
         int sel = ((JComboBox)evt.getSource()).getSelectedIndex();
         System.out.println("ActionListener " + sel + " " + ((JComboBox)evt.getSource()).getItemAt(sel) + " " + cmbMgmt.getItemAt(sel));
         Mgmt_Class mClass = (Mgmt_Class)mgmtVct.get(sel - 1);
         System.out.println("From Vector " + mClass.getAddress1() + " " + mClass.getAddress2() + " " + mClass.getManagementCode());
         txtMgmtAddr1.setText(mClass.getAddress1());
         txtMgmtAddr2.setText(mClass.getAddress2());
         txtMgmtCity.setText(City.getCityName(mClass.getCityCode()));
         System.out.println("\n\nListener " + ((JComboBox)evt.getSource()).getSelectedItem() + " " + (((JComboBox)evt.getSource()).getSelectedIndex()) );
         int mCode = mClass.getManagementCode();
         cnt = new Mgmt_Contact(mCode);
    System.out.println("\n After new Mgmt_Contact constructor");
         } // end of JComboBox
    } // end of actionPerformed
    } // end of Mgmt_Header
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.io.*;
    public class Mgmt_Contact extends JPanel implements KeyListener{
         private Mgmt_Contact_Class contact = null;
         private DefaultFocusManager mgr = null;
         private JTextField txtFName = null;
         private JTextField txtLName = null;
         private JTextField txtAddr1 = null;
         private JTextField txtAddr2 = null;
         private JButton btnUpd = null;
         private JButton btnNew = null;
         private JButton btnDel = null;
         private JButton btnNext = null;
         private JButton btnPrior = null;
         private JButton btnSel = null;
         private JPanel cntct = null;
         private JPanel pWork = null;
         private JPanel pWest = null;
         private JPanel pEast = null;
         private JPanel pNorth = null;
         private JPanel pSouth = null;
         private JPanel pCenter = null;
         public Mgmt_Contact() {
         System.out.println("\n MgmtContact default constructor");
              contact = new Mgmt_Contact_Class();
              bldPage();
         System.out.println("\n ******* After bldPage() routine");
         public Mgmt_Contact(int mCode) {
    System.out.println("\n MgmtContact second constructor " + mCode);
         Vector mgmtVct = new Vector();
         contact = new Mgmt_Contact_Class();
         mgmtVct = contact.bldMgmtContactTbl(mCode);
         contact =(Mgmt_Contact_Class)mgmtVct.get(0);
    System.out.println("\n ******* Management Contact Table *** " + contact.getFirstName());          
         bldPage();
    System.out.println("\n ******* After bldPage() routine");
         public void bldPage(){
    System.out.println("\n MgmtContact bldPage ");
              cntct = new JPanel();
              cntct.setLayout(new BorderLayout());
              pWest = new JPanel();
              pWest.setLayout(new GridLayout(0,1));
              pCenter = new JPanel();
              pCenter.setLayout(new GridLayout(0,1));
              pNorth = new JPanel();
              pNorth.setLayout(new FlowLayout(FlowLayout.CENTER));
              pSouth = new JPanel();
              pSouth.setLayout(new FlowLayout());
              pWork = new JPanel();
              pWork.setLayout(new FlowLayout(FlowLayout.LEFT));
              pWest.add(new JLabel("First :"));
              txtFName = new JTextField(15);
              txtFName.setText(contact.getFirstName());
    System.out.println("\n First Name " + txtFName.getText() + " " + contact.getFirstName());
              txtFName.setPreferredSize(new Dimension(200,27));
              txtFName.addKeyListener(this);
              txtFName.setName("txtFName");
              pWork.add(txtFName);
              pWork.add(new JLabel("Last :"));
              txtLName = new JTextField(15);
              txtLName.setText(contact.getLastName());
              txtLName.setPreferredSize(new Dimension(200,27));
              txtLName.setName("txtLName");     
              txtLName.addKeyListener(this);
              pWork.add(txtLName);
              pCenter.add(pWork);
              pWork = new JPanel();
              pWork.setLayout(new FlowLayout(FlowLayout.LEFT));
              pWest.add(new JLabel("Address :"));
              txtAddr1 = new JTextField(15);
              txtAddr1.setText(contact.getAddress1());
              txtAddr1.setPreferredSize(new Dimension(200,27));
              txtAddr1.addKeyListener(this);
              txtAddr1.setName("txtAddr1");
              pWork.add(txtAddr1);
              pWork.add(new JLabel(" "));
              txtAddr2 = new JTextField(15);
              txtAddr2.setText(contact.getAddress2());
              txtAddr2.setPreferredSize(new Dimension(200,27));
              txtAddr2.setName("txtAddr2");
              txtAddr2.addKeyListener(this);
              pWork.add(txtAddr2);
              pCenter.add(pWork);
              pWork = new JPanel();
              pWork.setLayout(new FlowLayout(FlowLayout.LEFT));
              btnUpd = new JButton("Update");
              btnUpd.addActionListener(new ButtonListener());
              btnDel = new JButton("Delete");
              btnDel.addActionListener(new ButtonListener());
              btnNew = new JButton(" Add ");
              btnNew.addActionListener(new ButtonListener());
              btnNext = new JButton(" Next ");
              btnNext.addActionListener(new ButtonListener());
              btnPrior = new JButton(" Prior ");
              btnPrior.addActionListener(new ButtonListener());
              btnSel = new JButton(" Select ");
              btnSel.addActionListener(new ButtonListener());
              pSouth.add(btnNew);
              pSouth.add(btnUpd);
              pSouth.add(btnDel);
              pSouth.add(btnNext);
              pSouth.add(btnPrior);
              pSouth.add(btnSel);
              cntct.add("West", pWest);
              cntct.add("Center", pCenter);
              cntct.add("South", pSouth);
              add(cntct);
         class ButtonListener implements ActionListener{
         public void actionPerformed(ActionEvent e){
    System.out.println("ButtonListener " + e.getActionCommand() + " " +
              contact.getString());
    // KeyListener Interface
         public void keyPressed(KeyEvent e){
         public void keyReleased(KeyEvent e){
              mgr = new DefaultFocusManager();
              Component comp = e.getComponent();
              Object obj = ((JTextField)e.getSource());
              if ((ColUtils.isMaxField(obj))){
              mgr.focusNextComponent(comp);
         } // end of KeyReleased
         public void keyTyped(KeyEvent e){
              char num = e.getKeyChar();
              Object obj = ((JTextField)e.getSource());
              if (ColUtils.isDataValid(num, obj)){
              else {
              e.consume();
              System.out.println(num + " Rejected Data");
         } // end of keyTyped
    } // end of Mgmt_Contact class

  • JTabbedPane with JScrollPane

    The application uses a JTabbedPane, each Tab contains a JScrollPane, the TopComponent contains the same Class with different Classes for the BottomComponent. Each BottomComponent is a separate class and relates to a different table. How can I interface with with the other classes without knowing which Tab is active?

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Property_Features extends JPanel implements ActionListener{
         private JTextArea txtFeature;
         private JLabel image;
         private JButton btnNew = null;
         private JButton btnUpd = null;
         private JButton btnDel = null;
         private JToolTip toolTip = null;
         private Prop_Header propHdr = null;
         private JPanel fPanel = null;
         private JPanel wPanel = null;
         private Box vertBox;     
         private Box topBox;     
         private Box midBox;     
         private Box botBox;     
    public Property_Features(){
         toolTip = new JToolTip();
         vertBox = Box.createVerticalBox();
         topBox = Box.createHorizontalBox();
         midBox = Box.createHorizontalBox();
         botBox = Box.createHorizontalBox();
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         txtFeature = new JTextArea(5,50);
         txtFeature.setFont(new Font("SansSerif", Font.PLAIN, 14));
         txtFeature.setLineWrap(true);
         txtFeature.setWrapStyleWord(true);
         txtFeature.setEditable(true);
         txtFeature.setBorder(BorderFactory.createTitledBorder(" Describe the Property Features"));
         toolTip.setComponent(txtFeature);
         txtFeature.setToolTipText("Enter Property Feature of Major Interest");
         wPanel.add(txtFeature);
         topBox.add(wPanel);
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         btnNew = new JButton(" Add ");
         btnNew.addActionListener(this);
         toolTip.setComponent(btnNew);
         btnNew.setToolTipText("Add Property Feature Information");
         btnUpd = new JButton("Update");
         btnUpd.addActionListener(this);
         toolTip.setComponent(btnUpd);
         btnUpd.setToolTipText("Update Property Feature Information");
         btnDel = new JButton("Delete");
         btnDel.addActionListener(this);
         toolTip.setComponent(btnDel);
         btnDel.setToolTipText("Delete Property Information");
         wPanel.add(btnNew);
         wPanel.add(btnUpd);
         wPanel.add(btnDel);
         midBox.add(wPanel);
         wPanel = new JPanel();
         wPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         image = new JLabel("", new      ImageIcon("c:/ATC_Application/images/skiing.jpg"), JLabel.CENTER);
         wPanel.add(image);
         botBox.add(image);
         vertBox.add(topBox);
         vertBox.add(midBox);
         vertBox.add(botBox);
         JSplitPane split = new JSplitPane();
         split.setOrientation(JSplitPane.VERTICAL_SPLIT);
         Prop_Header propHdr = new Prop_Header();
         split.setTopComponent(propHdr);
         split.setBottomComponent(vertBox);
         JScrollPane scrollPane = new JScrollPane(vertBox,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
         scrollPane.setPreferredSize(new Dimension(650,400));
         split.add(scrollPane);
         add(split);
    } // end of Property_Features constructor
    // ActionListener Interface
         public void actionPerformed(ActionEvent e){
              System.out.println("Action Listener " + e.getActionCommand());
    } // end of class
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Prop_Header extends JPanel implements ActionListener{
    private JComboBox cmbProp;
    private JTextField txtPropCode;
    private JTextField txtPropAddr1;
    private JTextField txtPropAddr2;
    private JTextField txtPropCity;
    private JTextField txtPropState;
    private JButton sel;
    private JLabel lblBlk;
    private JPanel pWork;
    private Box vertBox;     
    private Box topBox;     
    private Box midBox;     
    private Box botBox;     
    JToolTip toolTip = null;
    public Prop_Header(){
         vertBox = Box.createVerticalBox();
         topBox = Box.createHorizontalBox();
         midBox = Box.createHorizontalBox();
         botBox = Box.createHorizontalBox();
         cmbProp = new JComboBox();
         cmbProp.addItem(" ");
         cmbProp.setEditable(false);
         cmbProp.setBackground(Color.white);
         cmbProp.setPreferredSize(new Dimension(250,27));
         cmbProp.setFont(new Font("Times-Roman",Font.PLAIN,12));
         cmbProp.addActionListener(this);
         txtPropCode = new JTextField(5);
         txtPropCode.setFont(new Font("Times-Roman",Font.PLAIN,12));
         txtPropCode.setPreferredSize(new Dimension(5,27));
         txtPropCode.addActionListener(this);
         lblBlk = new JLabel(" ");
         sel = new JButton("Select");
         sel.addActionListener( this);
         toolTip = new JToolTip();
         toolTip.setComponent(cmbProp);
         cmbProp.setToolTipText("Select Property Name & Press
    Select button ");
         toolTip.setComponent(txtPropCode);
         txtPropCode.setToolTipText("Enter Property Code & Press
    Select Button ");
         toolTip.setComponent(sel);
         sel.setToolTipText("Display Property Information Based on
    Name or Code Entered ");
         pWork = new JPanel();
         pWork.setLayout(new FlowLayout(FlowLayout.CENTER));
         pWork.setBorder(BorderFactory.createTitledBorder(" Select
    Property Name or Enter Code "));
         pWork.add(new JLabel("Name: "));
         pWork.add(cmbProp);
         pWork.add(new JLabel(" Code: "));
         pWork.add(txtPropCode);
         pWork.add(lblBlk);
         pWork.add(sel);
         topBox.add(pWork);
         txtPropAddr1 = new JTextField("Address line 1",15);
         txtPropAddr1.setEditable(false);
         txtPropAddr2 = new JTextField("Address line 2",15);
         txtPropAddr2.setEditable(false);
         txtPropCity = new JTextField("City",15);
         txtPropCity.setEditable(false);
         txtPropState = new JTextField("State",3);
         txtPropState.setEditable(false);
         toolTip.setComponent(txtPropAddr1);
         txtPropAddr1.setToolTipText("First Address Line of Property");
         toolTip.setComponent(txtPropAddr2);
         txtPropAddr2.setToolTipText("Second Address Line of Property");
         toolTip.setComponent(txtPropCity);
         txtPropCity.setToolTipText("City Name of Property location");
         toolTip.setComponent(txtPropState);
         txtPropState.setToolTipText("State Code of Property location");
         midBox.add(midBox.createVerticalStrut(10));
         botBox.add(new JLabel("Address:"));
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropAddr1);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropAddr2);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropCity);
         botBox.add(topBox.createHorizontalStrut(10));
         botBox.add(txtPropState);
         vertBox.add(topBox);
         vertBox.add(midBox);
         vertBox.add(botBox);
         add(vertBox);
    } // end of constructor
         public void actionPerformed(ActionEvent evt){
         } // end of actionPerformed
    } // end of Prop_Header

Maybe you are looking for

  • BADI MB_DOCUMENT_BADI dump error

    Hi all, am using BADI : MB_DOCUMENT_BADI,method MB_DOCUMENT_BEFORE_UPDATE,to have checks in MB1A(Goods Issue transaction).I have written a code to check some values,after checking and raising an error message if I press enter the following dump error

  • PDF Image Extractor questions

    I have 2 questions: 1) I mentioned in a previous post that I'm working on a PDF image extractor, mine is a commercial solution so I would like it to be as competitive as possible.  I've researched many pdf image extractor tools and I've seen lots of

  • 18 month old original i-pad switches on but screen resolution not good and can only just see the icons has the screen gone?

    18 month old original i-pad switches on but screen resolution not good and can only just see the icons has the screen gone?

  • ITunes Store in Francais?

    When I go the iTunes Store, the main page is in French. How did this happen and how do I correct this?

  • Can I change a template animation?

    I would like to change the color of the brush that goes across the bottom of the screen in the apple template "brush cover" More specifically I would like it to be black with a color at the end that looks like paint. Is this possible and if so how ca