是否可以将标题放在JComponent的左侧(或右侧)?
我指的不是辩解,而是真正的立场。
我在与JComponent相关的TitledBorder上尝试了setTitlePosition(TitledBorder.LEFT),但似乎不起作用(可能只是为了证明原因?)
如果这是不可能的,有没有人有一个非常简单的方法来达到这个效果?
我想写一些这样的代码:
TitledBorder titleB = new TitledBorder(description);
titleB.setTitlePosition(LEFT); 发布于 2011-03-08 20:21:16
我猜你得到了一个IllegalArgumentException,因为LEFT显然不是一个有效的位置。这是TitledBorder.setTitlePosition的代码:
switch (titlePosition) {
case ABOVE_TOP:
case TOP:
case BELOW_TOP:
case ABOVE_BOTTOM:
case BOTTOM:
case BELOW_BOTTOM:
case DEFAULT_POSITION:
this.titlePosition = titlePosition;
break;
default:
throw new IllegalArgumentException(titlePosition +
" is not a valid title position.");
}我不认为设置组件的标题左/右存在OOTB。但是,您可以创建自己的边框,或者(可能)更简单地创建您自己的组件,该组件具有一个垂直显示文本的标签,然后使用BorderLayout LEFT/RIGHT将此自定义组件添加到面板中。
你好,
斯蒂芬
发布于 2011-03-08 19:41:50
有几个JComponent子类,如用于标签和按钮的子类,包括设置组件标题文本相对于其图标的水平和垂直位置的方法。此example显示DefaultTableCellRenderer,它是JLabel的子类,标签在右侧:
this.setHorizontalAlignment(JLabel.RIGHT);https://stackoverflow.com/questions/5231724
复制相似问题