Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

No scroll arrows for JTabbedPane JApplet

Posted on 2007-03-22
14
Medium Priority
?
689 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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 1000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

670 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