我有一個帶有TitledBorder的JPanel,但面板的內容比邊框中的標題窄,標題被截斷。 我正在使用BoxLayout作爲here所示的JPanel,注意寬度的手動設置。我試圖根據TitledBorder getMinimumSize()函數以及其組件的寬度設置面板的最小,最大和首選寬度,但都不起作用。唯一有效的工作是使用盒裝填料,但引入了不希望的縮進。標題截斷JPanel TitledBorder - Java swing
任何方式顯示完整的標題,而不管它包含的內容?
this.jpCases.setLayout(new javax.swing.BoxLayout(this.jpCases, javax.swing.BoxLayout.LINE_AXIS));
List<Category> categories = db.getCategories();
for (Category cat : categories) {
JPanel jp = new JPanel();
TitledBorder tb = BorderFactory.createTitledBorder(cat.getDescription());
jp.setBorder(tb);
jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS));
jp.setAlignmentY(Component.TOP_ALIGNMENT);
jp.setAlignmentX(Component.LEFT_ALIGNMENT);
List<Case> cases = db.getCasesByCategoryId(cat.getId());
for (Case c : cases) {
JRadioButton jrbCase = new JRadioButton();
jrbCase.setText(c.getDescription());
jrbCase.setToolTipText(c.getText());
jrbCase.setMaximumSize(tb.getMinimumSize(jp));
bgCases.add(jrbCase);
jp.add(jrbCase);
}
//jp.add(new Box.Filler(tb.getMinimumSize(jp), tb.getMinimumSize(jp), tb.getMinimumSize(jp)));
this.jpCases.add(jp);
}
爲了更好地幫助越早,張貼[SSCCE(HTTP:// pscode.org/sscce.html)。 –