JTabbedPane标签垂直改成水平

a2068879 2009-12-15 10:27:48
现在有五个标签 效果是这样的
标 标 标 标 标
签 签 签 签 签
1 2 3 4 5


我想要的效果是(标签水平)

标签1 标签2 标签3 标签4 标签5
...全文
313 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
huang_w 2009-12-16
  • 打赏
  • 举报
回复
你用到布局了吗?是不是布局设置成竖直方式显示了?
a2068879 2009-12-16
  • 打赏
  • 举报
回复
我自己往里面添加标签值就是 水平的 原来的值还是垂直的
a2068879 2009-12-15
  • 打赏
  • 举报
回复
我要是能找到是在什么地方写的 就不麻烦大家了
我想知道有没有这样的属性 我好根据这个属性去找这个代码
realreachard 2009-12-15
  • 打赏
  • 举报
回复
贴代码上来
a2068879 2009-12-15
  • 打赏
  • 举报
回复
包括里面的字体 都是垂直的 看的时候需要侧着看
a2068879 2009-12-15
  • 打赏
  • 举报
回复
肯定不是格子设子太小问题 因为放到左侧 也是垂直的
realreachard 2009-12-15
  • 打赏
  • 举报
回复
查看布局,查看label的size设置
justinavril 2009-12-15
  • 打赏
  • 举报
回复
感觉是不是你默认的面板的大小小了点 导致你标签字体排版的时候是竖着的?
a2068879 2009-12-15
  • 打赏
  • 举报
回复
这个是我的代码
ALMModelObject theWorkspaceModel = ALMApplication.message_getWorkspace();
ALMController theWorkspaceController = theWorkspaceModel.newController();
theApplicationController.registerFolder(CoreConstants.keyResultFolders, theWorkspaceController);
ALMTreeBuilderNode theTreeBuilder = new ALMTreeBuilderNode(theWorkspaceController, ALMControllerTreeNodeFactory.sFactory);
theTreeBuilder.setRecursiveBuild(true);

DefaultNamedObject theTabDelegate = new DefaultNamedObject(almLocalized("lbl_resultfolders"));
ImageIcon theIcon = getBundle().getImageIcon("icon-resultfolders.png");
if (theIcon != null)
theTabDelegate.setIcon(theIcon);
theApplicationController.registerTabView(1000, CoreConstants.keyResultFolders,theTabDelegate, theTreeBuilder);
}
a2068879 2009-12-15
  • 打赏
  • 举报
回复
谢谢这么多的代码 就是不是知道干什么用的 一个中国字都没有
huntor 2009-12-15
  • 打赏
  • 举报
回复
http://blog.elevenworks.com/?p=4Step 7: Specify the size of the tabs

In order to specify the size of the tabs we need to override the calculateTabHeight method and the calculateTabWidth method. We can also use the calculateTabHeight method to enforce the fact that a tab will always be a height that is divisible by two. This will make sure that the angled line on the right hand side of the tabs always looks good (unlike the screenshots from the previous step).

	protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight)
{
int vHeight = fontHeight;
if (vHeight % 2 > 0)
{
vHeight += 1;
}
return vHeight;
}

protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics)
{
return super.calculateTabWidth(tabPlacement, tabIndex, metrics) + metrics.getHeight();
}

huntor 2009-12-15
  • 打赏
  • 举报
回复
http://java-swing-tips.blogspot.com/2008/03/horizontally-fill-tab-of-jtabbedpane.html
class ClippedTitleTabbedPane extends JTabbedPane {
private final Insets tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
private final Insets tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");
public ClippedTitleTabbedPane() {
super();
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
initTabWidth();
}
});
}
@Override
public void insertTab(String title, Icon icon, Component component, String tip, int index) {
super.insertTab(title, icon, component, tip==null?title:tip, index);
JLabel label = new JLabel(title, JLabel.CENTER);
Dimension dim = label.getPreferredSize();
label.setPreferredSize(new Dimension(0, dim.height+tabInsets.top+tabInsets.bottom));
setTabComponentAt(index, label);
initTabWidth();
}
public void initTabWidth() {
Insets insets = getInsets();
int areaWidth = getWidth() - tabAreaInsets.left - tabAreaInsets.right
- insets.left - insets.right;
int tabCount = getTabCount();
int tabWidth = tabInsets.left + tabInsets.right + 3;
switch(getTabPlacement()) {
case LEFT: case RIGHT:
tabWidth = (int)(areaWidth/4) - tabWidth;
break;
case BOTTOM: case TOP: default:
tabWidth = (int)(areaWidth/tabCount) - tabWidth;
}
for(int i=0;i < tabCount;i++) {
JLabel l = (JLabel)getTabComponentAt(i);
if(l==null) break;
l.setPreferredSize(new Dimension(tabWidth, l.getPreferredSize().height));
}
}
@Override
public synchronized void repaint() {
initTabWidth();
super.repaint();
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧