问题描述
白线:
我使用 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 (将#修改为@)