微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Java Swing JTabbedPane 移除白色边框

如何解决Java Swing JTabbedPane 移除白色边框

如何去除给定图片中的白线。

白线:

https://i.stack.imgur.com/7CU9h.png

我使用 Swing 并为 tabbedPane 编写了一个自定义 UI。 我试过了: tabbedPane.setBorder(BorderFactory.createLineBorder(Color.black,1)); 但这不起作用。

我也阅读了 BasicTabbedPaneUI 的文档,但在那里找不到更多帮助。

我的自定义用户界面:

public class CustomTabbedPaneUI extends BasicTabbedPaneUI {

private int inclTab = 4;
private int anchoFocoV = inclTab;
private int anchoFocoH = 4;
private int anchoCarpetas = 18;
private polygon shape;

public static ComponentUI createUI(JComponent c) {
    return new CustomTabbedPaneUI();
}

@Override
protected void installDefaults() {
    super.installDefaults();
    tabAreaInsets.right = anchoCarpetas;
}

@Override
protected void paintTabArea(Graphics g,int tabPlacement,int selectedindex) {
    super.paintTabArea(g,tabPlacement,selectedindex);
}

@Override
protected void paintTabBackground(Graphics g,int tabIndex,int x,int y,int w,int h,boolean isSelected) {
    Graphics2D g2D = (Graphics2D) g;
    int xp[] = null;
    int yp[] = null;
    
    xp = new int[] {x,x,x + w,x};
    yp = new int[] {y,y + h - 1,y,y};
    shape = new polygon(xp,yp,xp.length);
    g2D.setColor(Color.BLACK);
    g2D.setPaint(Color.BLACK);
    g2D.fill(shape);
}

@Override
protected void paintText(Graphics g,Font font,FontMetrics metrics,String title,Rectangle textRect,boolean isSelected) {
    super.paintText(g,font,metrics,tabIndex,title,textRect,isSelected);
    int mnemIndex = tabPane.getdisplayedMnemonicIndexAt(tabIndex);
    g.setColor(Color.WHITE);
    BasicGraphicsUtils.drawStringUnderlineCharat(g,mnemIndex,textRect.x,textRect.y + metrics.getAscent());
}

@Override
protected int calculateTabWidth(int tabPlacement,FontMetrics metrics) {
    return 20 + inclTab + super.calculateTabWidth(tabPlacement,metrics);
}

@Override
protected int calculateTabHeight(int tabPlacement,int fontHeight) {
    if (tabPlacement == LEFT || tabPlacement == RIGHT) {
        return super.calculateTabHeight(tabPlacement,fontHeight);
    } else {
        return anchoFocoH + super.calculateTabHeight(tabPlacement,fontHeight);
    }
}

@Override
protected void paintTabBorder(Graphics g,boolean isSelected) {
    
}

@Override
protected void paintFocusIndicator(Graphics g,Rectangle[] rects,Rectangle iconRect,boolean isSelected) {
    if (tabPane.hasFocus() && isSelected) {
        g.setColor(Color.DARK_GRAY);
        g.drawpolygon(shape);
    }
}

protected void paintContendBorder(Graphics g,int selectedindex) {
    super.paintContentBorder(g,selectedindex);
}
}

需要更多信息时,请告诉我。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。