如何禁用JSplitPane箭头按钮

时间:2010-10-22 13:51:15

标签: java swing jbutton jsplitpane

如何禁用(灰显)JSplitPane上的箭头按钮。我知道如何从BasicSplitPaneDivider获取按钮:

final int UP_ARROW = 0;
final BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI();
final BasicSplitPaneDivider divider = ui.getDivider();
final JButton upArrowButton = (JButton) divider.getComponent(UP_ARROW);

,但是当我尝试upArrowButton.setEnabled(false)时,它不会使向上箭头变灰,但会禁用它。我希望用户能够获得禁用向上箭头按钮的视觉反馈。我确实尝试了upArrowButton.getAction().setEnabled(false),但它不起作用(NullPointerException)。

请帮忙

2 个答案:

答案 0 :(得分:4)

您是否尝试过setOneTouchExpandable(false)

答案 1 :(得分:1)

final int UP_ARROW = 0;
final BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI();
final BasicSplitPaneDivider divider = ui.getDivider();
final JButton upArrowButton = (JButton) divider.getComponent(UP_ARROW);

upArrowButton.setVisible(false);

这项工作对我来说