Solved

No scroll arrows for JTabbedPane JApplet

Posted on 2007-03-22
14
681 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
  • 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
 
LVL 30

Expert Comment

by:mayankeagle
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:mayankeagle
ID: 18776343
Performance wise?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
pairstar challenge 2 42
json example 39 115
Modeling a class in java 5 33
what is a "java.lang.System Property"   ? 20 41
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now