2012-03-15 75 views

回答

3

没有,没有覆盖整个BacisTabbedPaneUI直接不可能的,所有的例子都是不同的质量(外观和本地OS非常敏感),very good example by aephyr

我的看法是JTabbedPane的*** JComponent的,有趣的例子用器具玻璃面板(您设置了一些边界JMenuBar的如提出etchech &线边框??? :-)

疯狂和肮脏的黑客

enter image description here

enter image description here

从代码

import java.awt.ComponentOrientation; 
import java.awt.Container; 
import java.awt.Dimension; 
import java.awt.GridBagConstraints; 
import java.awt.GridBagLayout; 
import java.awt.Insets; 
import java.awt.Rectangle; 
import javax.swing.Box; 
import javax.swing.JFrame; 
import javax.swing.JMenu; 
import javax.swing.JMenuBar; 
import javax.swing.JPanel; 
import javax.swing.JTabbedPane; 
import javax.swing.SwingUtilities; 

public class TabbedPaneWithManuBar { 

    public void makeUI() { 
     JTabbedPane tabbedPane = new JTabbedPane(); 
     tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 
     for (int i = 0; i < 20; i++) { 
      JPanel panel = new JPanel(); 
      panel.setName("tab" + (i + 1)); 
      panel.setPreferredSize(new Dimension(600, 100)); 
      tabbedPane.add(panel); 
     } 
     JFrame frame = new JFrame(); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.add(tabbedPane); 
     frame.pack(); 
     Rectangle tabBounds = tabbedPane.getBoundsAt(0); 
     Container glassPane = (Container) frame.getRootPane().getGlassPane(); 
     glassPane.setVisible(true); 
     glassPane.setLayout(new GridBagLayout()); 
     GridBagConstraints gbc = new GridBagConstraints(); 
     gbc.weightx = 1.0; 
     gbc.weighty = 1.0; 
     gbc.fill = GridBagConstraints.NONE; 
     gbc.insets = new Insets(tabBounds.y + 23, 0, 0, 5); 
     gbc.anchor = GridBagConstraints.NORTHEAST; 
     JMenuBar menuBar = new JMenuBar(); 
     menuBar.add(createMenu("Menu Example 1")); 
     menuBar.add(createMenu("Menu Example 1")); 
     menuBar.add(createMenu("Menu Example 1")); 
     menuBar.add(Box.createHorizontalGlue()); 
     menuBar.add(createMenu("About")); 
     menuBar.setPreferredSize(new Dimension(menuBar.getPreferredSize().width , (int) tabBounds.getHeight() - 2)); 
     glassPane.add(menuBar, gbc); 
     //JButton button = new JButton("My Button Position"); 
     //button.setPreferredSize(new Dimension(button.getPreferredSize().width, (int) tabBounds.getHeight() - 2)); 
     //glassPane.add(button, gbc); 
     frame.setLocationRelativeTo(null); 
     frame.setVisible(true); 
    } 

    private JMenu createMenu(String title) { 
     JMenu m = new JMenu(title); 
     m.add("Menu item #1 in " + title); 
     m.add("Menu item #2 in " + title); 
     m.add("Menu item #3 in " + title); 
     if (title.equals("About")) { 
      m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
     } 
     return m; 
    } 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable() { 

      @Override 
      public void run() { 
       new TabbedPaneWithManuBar().makeUI(); 
      } 
     }); 
    } 
} 
+0

@Ofek罗恩1.使用了玻璃面板适当布局管理,2.然后(例如),您可以覆盖所有需要的矩形从ConttentPane,(看到我的浮动JMenu的JTabbedPane的布局在GlassPane中)3.给GLassPane一些支持trapsparency或transluceny(更好)的JComponent(带有背景或图标的JPanel或nonopaque JLabel)4. RootPane代码错误,(jPanel.add(jRootPane); - 为什么要创建一个新的ContentPane)5.不运行你的代码,不是删除后的理由 – mKorbel 2014-11-03 12:16:46

相关问题