简体   繁体   中英

java swing TabbedPane position tabheaders bottom right to left

I wonder if there is any possibility to position a Tabbed pane to the bottom right, I want to make to containers above each other, the one with the tablabels at the top right to left (no problem/default), and the other one with the tablabels at bottom (so far so good) starting from right to left. The design I imagine is:

| tab display                                 |
| tab display                                 |
| tab display                                 |
-----------------------------------------------
_________________________  | tab top | another|
| Bottom Tab| Second Tab|______________________
|                                              |

well, my ascy drawing capabilities are limited but I hope you get the picture. Is there any way, in wich I can add a layout manager to a tabbed pane to layout the tablabels? Where can I find an example of such? Goodling suggested to just use a menubar in combination with a CardLayout for the tabbed panes. However I have no clue how to draw a menubar so that it looks like tabs. (I just peeked into the swingtrail for custom drawing but it just goes on about the general possibility, besides If I do so I loose the styling capabilities. The only thing I can think off right now is to use a tabbed pane with no content and make it controll another container with a card layout via eventlisteners.

Any suggestions?

PS: I have to implement the solution with java 1.6

In this case you can to set ComponentOrientation for JTabbedPane

import java.awt.ComponentOrientation;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

public class TestTabbedPane extends JFrame {

    private static final long serialVersionUID = 1L;
    private JTabbedPane tabbedPane;

    public TestTabbedPane() {
        tabbedPane = new JTabbedPane();
        tabbedPane.setPreferredSize(new Dimension(300, 200));
        getContentPane().add(tabbedPane);
        JPanel panel = new JPanel();
        tabbedPane.add(panel, "null");
        JTextField one = new JTextField("one");
        tabbedPane.add(one, "one");
        JTextField two = new JTextField("two");
        //tabbedPane.add(two, "<html> T<br>i<br>t<br>t<br>l<br>e <br> 1 </html>");
        tabbedPane.add(two, "<html> Tittle  1 </html>");
        tabbedPane.setEnabledAt(2, false);
        tabbedPane.setTitleAt(2, "<html><font color="
                + (tabbedPane.isEnabledAt(2) ? "black" : "red") + ">"
                + tabbedPane.getTitleAt(2) + "</font></html>");
        tabbedPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
    }

    public static void main(String args[]) {
        TestTabbedPane frame = new TestTabbedPane();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}

check with setTabPlacement(JTabbedPane.TOP) method available are TOP , LEFT , BOTTOM , RIGHT

http://www.exampledepot.com/egs/javax.swing/tabbed_TpTabLoc.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM