sscce寻找 Nimbus L&f 的潜在回答者(通过使用另一个 L&f 不可能重现这个有趣的问题),以防 Containers#Size 将选项卡打包到两个或更多Lines
,
据我所知,aephyr 只有一种可能的解决方案(不覆盖 NimbusTabbedPaneUI )
来自 sscce
import java.awt.BorderLayout;
import javax.swing.*;
public class TabbedPane {
private static final long serialVersionUID = 1L;
public TabbedPane() {
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
JTabbedPane tb = new JTabbedPane();
//tb.setUI(new CustomTabbedPaneUI());
tb.add("Tab1", new JTextArea(10, 20));
tb.add("Tab2", new JTextArea(10, 20));
tb.add("Tab3", new JTextArea(10, 20));
tb.add("Tab4", new JTextArea(10, 20));
tb.add("Tab5", new JTextArea(10, 20));
jp.add(tb, BorderLayout.CENTER);
//add(jp, BorderLayout.CENTER);
//tb.setEnabledAt(1, false);
//tb.setEnabledAt(3, false);
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.add(jp, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception system) {
system.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
TabbedPane tP = new TabbedPane();
}
});
}
}