Solved

No scroll arrows for JTabbedPane JApplet

Posted on 2007-03-22
14
684 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

776 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