Solved

No scroll arrows for JTabbedPane JApplet

Posted on 2007-03-22
14
686 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap bin 2 41
Selenium docs api java index 3 48
Java basic valueOf question 1 29
Tagging and Merging on Branch 1 30
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

820 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