当按钮按下时,JButton背景和前景颜色滑动 [英] JButton background and foreground color swipe when button pressed

查看:712
本文介绍了当按钮按下时,JButton背景和前景颜色滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何一个可以帮助实现下面的东西?

Could any one help to implement below thing?

我有自定义按钮,我已经重载了paintComponent和plainText方法给我自己的样子。重写的主要重点是给我自己的风格的按钮。

I have custom button which i have overloaded the paintComponent and plainText method to give my own look. the main focus of overridden is to give my own style for buttons.

所以这里的要求是原来按钮背景是白色的,前景是黑色的,当用户按下按钮

so here the requirement is originally button background is white and foreground is black and when user press the button the color should revert like background as black and foreground as white.

如何实现这个?

推荐答案

您可以提供自己的 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.

这篇关于当按钮按下时,JButton背景和前景颜色滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆