Example usage for javax.swing JTabbedPane JTabbedPane

List of usage examples for javax.swing JTabbedPane JTabbedPane

Introduction

In this page you can find the example usage for javax.swing JTabbedPane JTabbedPane.

Prototype

public JTabbedPane(int tabPlacement, int tabLayoutPolicy) 

Source Link

Document

Creates an empty TabbedPane with the specified tab placement and tab layout policy.

Usage

From source file:Main.java

public JComponent makeUI() {
    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbedPane.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI() {
        @Override//  w  w w  .  jav a 2  s .c o  m
        protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
            return 32;
        }

        @Override
        protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex,
                Rectangle iconRect, Rectangle textRect) {
            if (tabIndex == 0) {
                rects[tabIndex].height = 30 + 1;
                rects[tabIndex].y = 32 - rects[tabIndex].height + 1;
            } else if (tabIndex == 1) {
                rects[tabIndex].height = 26 + 1;
                rects[tabIndex].y = 32 - rects[tabIndex].height + 1;
            }
            super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect);
        }
    });
    tabbedPane.addTab("000", new JLabel("ok"));
    tabbedPane.addTab("111", new JScrollPane(new JTable()));
    tabbedPane.addTab("222", new JSplitPane());

    return tabbedPane;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    textField1.requestFocusInWindow();//ww w.java  2 s  .  c om
    tab1.add(textField1);

    tab2.add(textField2);
    tab2.add(textField3);

    contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());

    tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
    tabbedPane.addTab("TAB 1", null, tab1, "I am TAB 1");
    tabbedPane.addTab("TAB 2", null, tab2, "I am TAB 2");

    focusButton = new JButton("CHANGE FOCUS");
    getRootPane().setDefaultButton(focusButton);
    focusButton.addActionListener(this);

    contentPane.add(tabbedPane, BorderLayout.CENTER);
    contentPane.add(focusButton, BorderLayout.PAGE_END);
    setContentPane(contentPane);
    pack();
    setVisible(true);
}

From source file:hr.fer.zemris.vhdllab.platform.support.SimplisticEclipseBasedApplicationPage.java

@Override
protected JComponent createControl() {
    projectExplorerPane = new JPanel(new BorderLayout());
    editorsPane = new JPanel(new BorderLayout());
    viewsTabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
    viewsTabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            // if we're adding a component, ignore change of active
            // component
            if (!addingView && getViewsTabbedPane().getSelectedIndex() >= 0) {
                setActiveComponent(getComponent(getViewsTabbedPane().getSelectedIndex()));
            }//  w ww. j a v  a2 s .  c o  m
        }
    });

    final double horizontalLocation = 0.15;
    final double verticalLocation = 0.75;
    final JSplitPane horizontalPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, projectExplorerPane,
            editorsPane);
    horizontalPane.setDividerLocation(horizontalLocation);
    final JSplitPane verticalPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, horizontalPane, viewsTabbedPane);
    verticalPane.setDividerLocation(verticalLocation);

    JPanel maximizedPanel = new JPanel(new BorderLayout());
    maximizedPanel.add(verticalPane, BorderLayout.CENTER);
    JPanel control = new JPanel(new BorderLayout());
    control.add(maximizedPanel, BorderLayout.CENTER);
    control.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            horizontalPane.setDividerLocation(horizontalLocation);
            verticalPane.setDividerLocation(verticalLocation);
        }
    });

    this.getPageDescriptor().buildInitialLayout(this);

    if (viewsTabbedPane.getTabCount() > 0) {
        viewsTabbedPane.setSelectedIndex(0);
    }

    Logger.getRootLogger().addAppender(new AppenderSkeleton() {
        @Override
        public boolean requiresLayout() {
            return false;
        }

        @Override
        public void close() {
        }

        @SuppressWarnings("synthetic-access")
        @Override
        protected void append(LoggingEvent event) {
            if (event.getLevel().equals(Level.INFO)) {
                Object message = event.getMessage();
                if (message != null) {
                    getActiveWindow().getStatusBar().setMessage(message.toString());
                }
            }
        }
    });
    return control;
}

From source file:hr.fer.zemris.vhdllab.view.TabbedEditorsView.java

@Override
protected JComponent createControl() {
    CommandManager commandManager = getActiveWindow().getCommandManager();
    CommandGroup commandGroup = commandManager.createCommandGroup("editorsMenu", new Object[] { "saveCommand",
            "saveAllCommand", "separator", "closeCommand", "closeOtherCommand", "closeAllCommand" });

    tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
    tabbedPane.setComponentPopupMenu(commandGroup.createPopupMenu());
    tabbedPane.addChangeListener(new ChangeListener() {
        @Override//from w  w  w .j a va2s  .  c o m
        public void stateChanged(ChangeEvent e) {
            if (!addingTab) {
                int index = tabbedPane.getSelectedIndex();
                container.setSelected(index);
            }
        }
    });
    return tabbedPane;
}

From source file:org.intermine.modelviewer.swing.ModelViewer.java

/**
 * Lays out the components within this panel and wires up the relevant
 * event listeners.// w w w .  j av a  2 s.c  o m
 */
private void init() {

    FileFilter xmlFilter = new XmlFileFilter();
    projectFileChooser = new JFileChooser();
    projectFileChooser.addChoosableFileFilter(xmlFilter);
    projectFileChooser.setAcceptAllFileFilterUsed(false);
    projectFileChooser.setFileFilter(xmlFilter);

    File lastProjectFile = MineManagerBackingStore.getInstance().getLastProjectFile();
    if (lastProjectFile != null) {
        projectFileChooser.setSelectedFile(lastProjectFile);
    }

    initButtonPanel();

    classTreeModel = new ClassTreeModel();
    classTree = new JTree(classTreeModel);
    classTree.setCellRenderer(new ClassTreeCellRenderer());
    classTree.setRootVisible(false);
    classTree.setShowsRootHandles(true);

    Box vbox = Box.createVerticalBox();
    vbox.add(new JScrollPane(classTree));
    vbox.add(buttonPanel);

    DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
    selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    classTree.setSelectionModel(selectionModel);

    classTree.addTreeSelectionListener(new ClassTreeSelectionListener());

    attributeTableModel = new AttributeTableModel();
    attributeTable = new AttributeTable(attributeTableModel);

    referenceTableModel = new ReferenceTableModel();
    referenceTable = new ReferenceTable(referenceTableModel);

    graphModel = new mxGraphModel();
    graph = new CustomisedMxGraph(graphModel);

    graphComponent = new mxGraphComponent(graph);
    graphComponent.setEscapeEnabled(true);

    JTabbedPane tableTab = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    tableTab.add(Messages.getMessage("tab.attributes"), new JScrollPane(attributeTable));
    tableTab.add(Messages.getMessage("tab.references"), new JScrollPane(referenceTable));

    JSplitPane rightSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableTab, graphComponent);

    JSplitPane mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, vbox, rightSplit);

    setOpaque(true);
    setLayout(new BorderLayout());
    add(mainSplit, BorderLayout.CENTER);

    rightSplit.setDividerLocation(150);
    mainSplit.setDividerLocation(200);

}

From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java

@Override
protected void startup() {
    // set the window icon:
    {//from  ww  w  .ja v a  2s.c  o  m
        final Image img;
        if (true)
            img = getContext().getResourceMap().getImageIcon("Application.icon").getImage();
        else {
            final ResourceMap r = getContext().getResourceMap();
            if (true)
                try {
                    img = ImageIO.read(this.getClass()
                            .getResource("/" + r.getResourcesDir() + "/" + r.getString("Application.icon")));
                } catch (final IOException e) {
                    throw new RuntimeException("Unhandled", e);
                }
            else
                img = Toolkit.getDefaultToolkit().createImage(this.getClass()
                        .getResource("/" + r.getResourcesDir() + "/" + r.getString("Application.icon")));
        }
        getMainFrame().setIconImage(img);
        // SystemTray tray = SystemTray.getSystemTray();
    }

    // File Filter
    jcxzPat = gui.createFileFilter("fileFilterJcxz", "jcz", "jcx");
    pngPat = gui.createFileFilter("fileFilterPng", "png");
    svgPat = gui.createFileFilter("fileFilterSvg", "svgz", "svg");

    getMainFrame().setJMenuBar(createMenuBar());

    final JComponent c = new JPanel();
    c.setLayout(new BorderLayout());
    tactics.setPreferredSize(new Dimension(400, 600));
    c.add(tactics, BorderLayout.CENTER);
    c.add(url, BorderLayout.NORTH);
    {
        final JPanel b = new JPanel();
        b.setLayout(new BorderLayout());
        final JTabbedPane t = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
        t.add("Rock", broomSwing);
        t.setMnemonicAt(0, 'R');
        t.add("Ice", curlerSwing);
        t.setMnemonicAt(1, 'I');
        t.add("Collission", new JLabel("TODO: Collission settings"));
        t.setMnemonicAt(2, 'C');
        b.add(t, BorderLayout.NORTH);
        if (false)
            b.add(new JLabel("TODO: Bird's eye view"), BorderLayout.CENTER);
        else
            b.add(birdPiccolo, BorderLayout.CENTER);
        c.add(b, BorderLayout.EAST);
    }

    show(c);
    view12Foot();
}