Solved

No scroll arrows for JTabbedPane JApplet

Posted on 2007-03-22
14
687 Views
Last Modified: 2012-05-05
I have a JApplet that has a JTabbedPane in it.  The applet is in a top frame on an HTML page.  I want tabs to scroll (have arrows) when the applet frame does not fit all tabs.

I added:
tabPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

STill I do not get the scroll arrows.  My tabs just keep disappearing.

Thanks.
0
Comment
Question by:akoifman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
14 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 18770400
Can you post some example code for your applet?  That *should* work afaik
0
 
LVL 92

Expert Comment

by:objects
ID: 18770449
its L&F dependant, which one are you using?
0
 

Author Comment

by:akoifman
ID: 18771176
public class Tab extends JApplet {

    private BorderLayout borderLayout = new BorderLayout();
    private GridLayout gridLayout = new GridLayout();


    public void init() {
        Logger.debug("Tab, init");

        loadingProgress = true;

        UIManager.getDefaults().put("TabbedPane.background", new Color(0xc8ddf2));
        UIManager.getDefaults().put("TabbedPane.selected", new Color(0x030e90));

        this.setLayout(borderLayout);

        tabPanel = new JTabbedPane();
        tabPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
     //   enableTabs(false);

        tabPanel.setFont(WmGlobals.TABS_FONT);

        this.add(tabPanel, java.awt.BorderLayout.NORTH);

        setTabs();
    }


   public void setTabs() {
        Logger.debug("Tab, setTabs");


        for (int i = 0; i < labels.length; i ++) {
            JPanel p  = new JPanel();
            p.setLayout(gridLayout);
            tabPanel.add(labels[i], p);

            JTabbedPane tabPanel2 = new JTabbedPane();
            tabPanel2.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

            tab2.put(new Integer(i), tabPanel2);

            p.add(tabPanel2);

            tabPanel2.setFont(WmGlobals.TABS_FONT2);
            tabPanel2.setBackground(new Color(0x2159ad));

            String []labels2 = TreeDefs.names2[i];
            for (int j = 0; j < labels2.length; j ++) {
                if (labels2[j] == null)
                    break;

                JPanel p2 = new JPanel();
                p2.setLayout(gridLayout);
                p2.setBackground(new Color(0x7badde));
                tabPanel2.add(getName(labels2[j], maxLen), p2);
            }

            tabPanel2.getModel().addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    tabSwitched2(e);
                }
            });

        }




        tabPanel.revalidate();

        tabPanel.getModel().addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                tabSwitched(e);
            }
        });

        tabPanel.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            tabMouseClicked(evt);
        }
        });

        loadingProgress = false;
    }



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 18772655
Just an idea - did you try putting the panel or tabbed pane into a JScrollPane?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 18772673
?  Wouldn't that make it worse?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18776343
Performance wise?
0
 

Author Comment

by:akoifman
ID: 18776487
I have no space for scrollpane scrollbar, it takes the entire row.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 250 total points
ID: 18779052
Right, I changed you code so that it would compile (the code you posted had loads of stuff that didn't exist)

Compiled it

And viewed it with:

    appletviewer Tab.java

And it seems to work fine...

Here's the code:

/*
<html><body><applet width="600" height="400" code="Tab.class"></applet></body></html>
*/
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.event.* ;

public class Tab extends JApplet {

    private BorderLayout borderLayout = new BorderLayout();
    private GridLayout gridLayout = new GridLayout();
    private JTabbedPane tabPanel ;
    private boolean loadingProgress = false ;

    public void init() {
        loadingProgress = true;
        UIManager.getDefaults().put("TabbedPane.background", new Color(0xc8ddf2));
        UIManager.getDefaults().put("TabbedPane.selected", new Color(0x030e90));
        this.setLayout(borderLayout);
        tabPanel = new JTabbedPane();
        tabPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        this.add(tabPanel, java.awt.BorderLayout.NORTH);
        setTabs();
    }


   public void setTabs()
   {
        for( int i = 0 ; i < 10 ; i++ )
        {
            JPanel p  = new JPanel();
            p.setLayout( gridLayout ) ;
            tabPanel.add( "label " + i, p ) ;

            JTabbedPane tabPanel2 = new JTabbedPane();
            tabPanel2.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

            p.add(tabPanel2);

            for( int j = 0 ; j < 10 ; j++ )
            {
                JPanel p2 = new JPanel();
                p2.setLayout(gridLayout);
                p2.setBackground(new Color(0x7badde));
                tabPanel2.add( "t" + j, p2);
            }
        }
        loadingProgress = false;
    }
}
0
 

Author Comment

by:akoifman
ID: 18785527
Hi Tim,

Thanks a lot for your answer.  This made me look into my html file and I noticed that an incorrect width=1000 (instead of 100%).  After I fixed this I get the scroll arrows.

I see one negative visual aspect of this change.  My tab applet has the border around the lower tabs.  Can this border be less visible?  When I had the applet width=1000 this border was hidden.  I tried the width=110%, but I seem to unable to hide it.

Can I change the lower tab background (area above and to the right of tabs) to match the frame border color?

Thanks,

Alex.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 18785802
Can you show a screenshot of before and after the change?  So I can see the border you mean?
0
 

Author Comment

by:akoifman
ID: 18788452
Can I send an attachment here?

Do you see a line between the first and second row of tabs?And there is a frame around the second row that I see in your applet example.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 18788610
I'm on a Mac at the moment, so I have a different look and feel to you I think...
0
 

Author Comment

by:akoifman
ID: 18788613
Can I see what you have?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Desingning Refactoring existing code 2 46
mysql jsp example issue 32 97
Java program running SQL query 5 68
maximize the sum of fractions 33 76
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question