且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当按钮按下时,JButton背景和前景颜色滑动

更新时间:2023-10-05 10:02:46

您可以提供自己的 UI实现并将其附加到正常的组件实例,而不是对Swing组件进行子类化以修改它们的外观和感觉。

Instead of subclassing Swing components to modify how they «look and feel», you can provide your own UI implementation and attach it to a normal component instance.

查看以下方法:

  • 'JComponent.setUI(ComponentUI ui)': method to set the UI strategy/decoration
  • ButtonUI: the UI used for rendering buttons
  • BasicButtonUI: basic implementation you can extend easily, overwrite paintButtonPressed or the other paint-methods to create your own button look.