2010-06-26 6 views
2

내 응용 프로그램에서 JTabbedPane을 사용하고 있습니다. 사용자 정의 클래스 "ContentPanel"의 인스턴스 인 두 개의 탭을 추가했습니다. 이것은 JPanel을 확장하고 배경, 경계선 등을 설정합니다. 기본적으로이 색상 표를 적용 할 각 JPanel의 속성을 설정하지 않아도됩니다. 나는 경계선이 나타날뿐만 아니라 다른 경계선 (적어도 내 화면에는 파란색이라고 생각한다)이이 경계선 주위에 나타나며 탭 "선택자"자체에 연결된다는 것을 알아 차릴 수있다. 적절한보기). 나는이 테두리를 금색/갈색 색 구성표에 대해 이상하게 보아서 변경하고 싶습니다. 누구든지이 일을하는 방법을 알고 있습니까? JTabbedPane.setBorder (테두리 b) 시도했지만 그 doesnt 작동합니다. 탭 셀렉터를 포함하여 전체적으로 경계선을 설정하기 만하면됩니다.JTabbedPane - 탭 주위에 기본 테두리를 설정합니다.?

이 문제에 도움을 주시면 매우 감사하겠습니다.

답변

12

이 색상은 Look & Feel에서 정의됩니다. BasicTabbedPaneUI의 코드를 보면 installDefaults()protected Color 인스턴스 변수 집합을 설정합니다. L & F에 정의 된 키도 여기에서 사용할 수 있습니다. 이 과정의 수도

myTabbedPane.setUI(new BasicTabbedPaneUI() { 
    @Override 
    protected void installDefaults() { 
     super.installDefaults(); 
     highlight = Color.pink; 
     lightHighlight = Color.green; 
     shadow = Color.red; 
     darkShadow = Color.cyan; 
     focus = Color.yellow; 
    } 
}); 

: 당신이 당신의 자신의 L & F 정의로까지 가고 싶지 않는 경우

protected void installDefaults() { 
    LookAndFeel.installColorsAndFont(tabPane, "TabbedPane.background", 
           "TabbedPane.foreground", "TabbedPane.font");  
    highlight = UIManager.getColor("TabbedPane.light"); 
    lightHighlight = UIManager.getColor("TabbedPane.highlight"); 
    shadow = UIManager.getColor("TabbedPane.shadow"); 
    darkShadow = UIManager.getColor("TabbedPane.darkShadow"); 
    //... 
    // a lot more stuff 
    //... 
} 

, 당신은 당신의 탭 창에서 사용자 정의 UI 대리자를 설정하는 기능을 가지고 해당 색상 설정을 변경하려고합니다. 설정된대로, 어느 vars가 어디에 사용되는지 볼 수 있습니다.

+0

네,이게 제가 필요로하는 것처럼 보입니다. 고마워요. 나는 문제가있을 때 다시 논평 할 것이다. 리차드 – ClarkeyBoy

+0

흠이 완전히 작동하지 않는 것 같습니다. BasicTabbedPaneUI의 모든 변수를 살펴보고 거기에 나열된 모든 색상을 설정했지만 밝은 파란색/청록색 경계선이 조금 더 얇습니다. 그것은 "선택자"탭과 같은 색입니다. – ClarkeyBoy

+3

그것을 해결했습니다 - UIManager.put ("TabbedPane.contentBorderInsets", 새로운 인세 트 (0, 0, 0, 0))을 사용한다고하는 elses 스레드를 발견했습니다. ; 네가 두는대로. 국경을 완전히 없앴습니다. 다시 한번 감사드립니다. 리차드 – ClarkeyBoy

1

영향 없음 L & F 및 JVM 런타임 시스템 전체 설정 코드 솔루션.

"고유 한"탭 분할 창에 대한 문제를 처리하기 위해 자체 탭 분할 창 클래스 및 중첩 된 탭 분할 창 UI 클래스를 만듭니다. 아래의 코드는 원본입니다 : (. 마지막 대답은 2010했지만,이 역시 유용 할 수 있습니다)

public class DisplayTabbedPane extends JTabbedPane implements 
    MouseListener, ChangeListener { 

    public DisplayTabbedPane() { 

     setTabPlacement(SwingConstants.BOTTOM); 

     // UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); 
     // works but is a JVM system wide change rather than a specific change 
     NoInsetTabbedPaneUI ui = new NoInsetTabbedPaneUI(); 

     // this will build the L&F settings for various tabbed UI components. 
     setUI(ui); 

     // override the content border insets to remove the tabbed-pane 
     // blue border around the pane 
     ui.overrideContentBorderInsetsOfUI(); 

    } 

    /** 
    * Class to modify the UI layout of tabbed-pane which we wish to override 
    * in some way. This modification only applies to objects of this class. 
    * Doing UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); 
    * would affect all tabbed-panes in the JVM run-time. 
    * 
    * This is free to use, no copyright but is "AS IS". 
    */ 
    class NoInsetTabbedPaneUI extends MetalTabbedPaneUI { 
     /** 
     * Create tabbed-pane-UI object to allow fine control of the 
     * L&F of this specific object. 
     */ 
     NoInsetTabbedPaneUI(){ 
      super(); 
     } 
     /** 
     * Override the content border insets of the UI which represent 
     * the L&F of the border around the pane. In this case only care 
     * about having a bottom inset. 
     */ 
     public void overrideContentBorderInsetsOfUI(){ 
      this.contentBorderInsets.top = 0; 
      this.contentBorderInsets.left = 0; 
      this.contentBorderInsets.right = 0; 
      this.contentBorderInsets.bottom = 2;   
     } 
    } 
    ........ 

} 
0

변경보고 "하는 UIManager"

  UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter", new BackgroundPainter(Color.white)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Enabled+MouseOver].backgroundPainter", new BackgroundPainter(Color.white)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Enabled+Pressed].backgroundPainter", new BackgroundPainter(Color.white)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Focused+MouseOver+Selected].backgroundPainter", new BackgroundPainter(Color.white)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Focused+Pressed+Selected].backgroundPainter", new BackgroundPainter(Color.white)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Focused+Selected].backgroundPainter", new BackgroundPainter(Color.GRAY)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[MouseOver+Selected].backgroundPainter", new BackgroundPainter(Color.white)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Pressed+Selected].backgroundPainter", new BackgroundPainter(Color.white)); 
      UIManager.getLookAndFeelDefaults().put("TabbedPane:TabbedPaneTab[Selected].backgroundPainter", new BackgroundPainter(Color.white)); 

BackgroundPainter 클래스와 느낌

public class BackgroundPainter implements Painter<JComponent> { 

private Color color = null; 

BackgroundPainter(Color c) { 
    color = c; 
} 

@Override 
public void paint(Graphics2D g, JComponent object, int width, int height) { 
    if (color != null) { 
     g.setColor(color); 
     g.fillRect(0, 0, width - 1, height - 1); 
    } 
} 

}

관련 문제