怎样创建类似JBuilder工具栏中的“|”,使用addSeparator() 好像不对

VincintCao 2003-03-24 09:16:53
使用addSeparator() 创建的分割好像只有一块空的区域,用来分割,但是没有竖条。
...全文
81 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
VincintCao 2003-03-25
  • 打赏
  • 举报
回复
没有人知道吗?加分!
VincintCao 2003-03-25
  • 打赏
  • 举报
回复
Sorry, 我试过了你的方法,效果不是最好,我已经上了javaranch去找了相关的帖子,并得到了答案。公布一下:
toolbar.add(new JSeparator(SwingConstants.VERTICAL));
JBuilder八成就是这样实现的

还有一个问题,放在ToolBar上的TextField会充满,我想让他不要充满,该怎么做?
VincintCao 2003-03-25
  • 打赏
  • 举报
回复
To gtlang78() :
谢了
gtlang78 2003-03-25
  • 打赏
  • 举报
回复
import javax.swing.*;

public class Separator extends JToolBar.Separator {
public Separator() {
this.setAlignmentX(0.5f);
this.setAlignmentY(0.5f);
}

public void paintComponent(Graphics g) {
Dimension s = getSize();

JToolBar toolbar = (JToolBar)getParent();
if (toolbar.getOrientation() == JToolBar.HORIZONTAL ) {
g.setColor( SystemColor.controlShadow );
g.drawLine( s.width/2, 0, s.width/2, s.height );

g.setColor( Color.white );
g.drawLine( s.width/2+1, 0, s.width/2+1, s.height );
}
else { // HORIZONTAL
g.setColor( SystemColor.controlShadow );
g.drawLine( 0, s.height/2, s.width, s.height/2 );

g.setColor( Color.white );
g.drawLine( 0, s.height/2+1, s.width, s.height/2+1);
}
}
}
shine333 2003-03-25
  • 打赏
  • 举报
回复
这应该是LookAndFeel的问题,默认的是没有的,window的LNF是有的

62,634

社区成员

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

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