修改Button的边框

在TinyLookAndFeel.java 的 protected void initComponentDefaults(UIDefaults table)  方法中设置

 

table.put("Button.border",
   new BorderUIResource.CompoundBorderUIResource(
    new TinyButtonBorder(),
    new BasicBorders.MarginBorder()));

 

 

 

TinyButtonBorder是继承AbstractBorder.java和实现UIResource.java 的类

 

 

public class TinyButtonBorder extends AbstractBorder implements UIResource {
	
	protected final Insets borderInsets = new Insets(2, 2, 2, 2);

	/**
	 * Draws the button border for the given component.
	 *
	 * @param mainColor The component to draw its border.
	 * @param g The graphics context.
	 * @param x The x coordinate of the top left corner.
	 * @param y The y coordinate of the top left corner.
	 * @param w The width.
	 * @param h The height.
	 */
	public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
		switch (Theme.derivedStyle[Theme.style]) {
			case Theme.TINY_STYLE :
				drawTinyBorder(c, g, x, y, w, h);
				break;
			case Theme.W99_STYLE :
				drawWinBorder(c, g, x, y, w, h);
				break;
			case Theme.YQ_STYLE :
				drawXpBorder(c, g, x, y, w, h);
				break;
		}
	}

	private void drawTinyBorder(Component c, Graphics g, int x, int y, int w, int h) {
	}

	private void drawWinBorder(Component c, Graphics g, int x, int y, int w, int h) {
		AbstractButton b = (AbstractButton)c;
		boolean isDefault = (c instanceof JButton) && (((JButton)c).isDefaultButton());
		
		if(b.getModel().isPressed() ||
			((b instanceof JToggleButton) && b.isSelected()))
		{
			g.setColor(Color.BLACK);
			g.drawRect(0, 0, w - 1, h - 1);
			
			g.setColor(Theme.buttonDarkColor[Theme.style].getColor());
			g.drawRect(1, 1, w - 3, h - 3);
			return;
		}
		else if(isDefault && b.isEnabled()) {
			g.setColor(Theme.buttonDefaultColor[Theme.style].getColor());
			g.drawRect(0, 0, w - 1, h - 1);
			x += 1; y += 1; w -= 1; h -= 1;
		}
		
		if(!b.isEnabled()) {
			g.setColor(Theme.buttonLightDisabledColor[Theme.style].getColor());
		}
		else {
			g.setColor(Theme.buttonLightColor[Theme.style].getColor());
		}
		g.drawLine(x, y, w - 2, y);
		g.drawLine(x, y + 1, x, h - 2);
		
		if(!b.isEnabled()) {
			g.setColor(Theme.buttonBorderDisabledColor[Theme.style].getColor());
		}
		else {
			g.setColor(Theme.buttonBorderColor[Theme.style].getColor());
		}
		g.drawLine(x, h - 1, w - 1, h - 1);
		g.drawLine(w - 1, y, w - 1, h - 1);
		
		if(!b.isEnabled()) {
			g.setColor(Theme.buttonDarkDisabledColor[Theme.style].getColor());
		}
		else {
			g.setColor(Theme.buttonDarkColor[Theme.style].getColor());
		}
		g.drawLine(x + 1, h - 2, w - 2, h - 2);
		g.drawLine(w - 2, y + 1, w - 2, h - 2);
	}

	private void drawXpBorder(Component c, Graphics g, int x, int y, int w, int h) {
		AbstractButton b = (AbstractButton)c;
		boolean isDefault = (c instanceof JButton) && (((JButton)c).isDefaultButton());
		boolean isComboBoxButton =
			Boolean.TRUE.equals(b.getClientProperty("isComboBoxButton"));

		if(isComboBoxButton) {
			if (!b.isEnabled()) {
				DrawRoutines.drawRoundedBorder(
					g, Theme.comboBorderDisabledColor[Theme.style].getColor(), x, y, w, h);
			}
			else {	
				DrawRoutines.drawRoundedBorder(
					g, Theme.comboBorderColor[Theme.style].getColor(), x, y, w, h);
	
				if(b.getModel().isPressed()) return;

				if(b.getModel().isRollover() && Theme.comboRollover[Theme.style]) {
					DrawRoutines.drawRolloverBorder(
						g, Theme.buttonRolloverColor[Theme.style].getColor(), x, y, w, h);
				}
			}
		}
		else {	// it's a normal JButton or a JSpinner button
			boolean isSpinnerButton =
				Boolean.TRUE.equals(b.getClientProperty("isSpinnerButton"));
			boolean paintRollover =
				(isSpinnerButton && Theme.spinnerRollover[Theme.style]) ||
				(!isSpinnerButton && Theme.buttonRollover[Theme.style]);
			
			if (!b.isEnabled()) {
				DrawRoutines.drawRoundedBorder(
					g, Theme.buttonBorderDisabledColor[Theme.style].getColor(), x, y, w, h);
			}
			else {	
				DrawRoutines.drawRoundedBorder(
					g, Theme.buttonBorderColor[Theme.style].getColor(), x, y, w, h);
	
				if(b.getModel().isPressed()) return;
				
				if(b.getModel().isRollover() && paintRollover) {
					DrawRoutines.drawRolloverBorder(
						g, Theme.buttonRolloverColor[Theme.style].getColor(), x, y, w, h);
				}
				else if(isDefault ||
					(Theme.buttonFocusBorder[Theme.style] && b.isFocusOwner()))
				{
					DrawRoutines.drawRolloverBorder(
						g, Theme.buttonDefaultColor[Theme.style].getColor(), x, y, w, h);
				}
			}
		}
	}

	/**
	 * Gets the border insets for a given component.
	 *
	 * @param c The component to get its border insets.
	 * @return Always returns the same insets as defined in <code>insets</code>.
	 */
	public Insets getBorderInsets(Component c) {
		return borderInsets;
	}
}

 

 

 

JButton去除边框 类似eclipse工具栏的效果,无悬浮,按钮无边框,悬浮时候呈现边框 立即下载

相关推荐

ExtJS 常用组件样式修改

这里主要介绍了ExtJS常用组件的样式修改,包括工具栏样式修改、菜单样式修改、树形菜单样式修改、表格样式修改、按钮样式修改等。

CSS3设置按钮的样式

平面按钮样式——现主流 在实际开发中,按钮的应用是必不可少 使用 CSS 来制作按钮,可以更有新意,更有趣,也可以自定义自己想要的样式 平面样式按钮的使用现在非常流行,并且符合无处不在的平面设计趋势 实现方式 .button { background-color: #4CAF50; /* Green */ border: none; color: white; padding: 15px 32px; text-align: center; text-dec

视觉软件 3万+

SAP COPA实战:手把手教你用CMOD增强搞定自定义特性派生(以客户字段为例)

本文详细介绍了在SAP COPA模块中通过CMOD增强实现自定义特性派生的全流程,以客户字段为例,展示了从特性设计、SPRO配置到特性派生逻辑实现的完整步骤。重点讲解了如何利用CMOD增强技术解决业务需求,提升获利能力段分析的灵活性和准确性。

weixin_30275415的博客 438

有趣的css - 边框动效按钮

交互感比较强的一个动效按钮。

设计师工作日常 1248

手把手教你玩转Infoseek舆情监测系统:从数据爬取到智能分析实战

别只会监测品牌名!一个有效的监测体系应该包括:// 完整的监测关键词策略brand: ["品牌名", "产品名", "缩写"],executives: ["CEO姓名", "高管姓名"],campaign: ["当前营销活动名称"],competitors: ["竞品A", "竞品B"],industry: ["行业通用关键词"],// 别忘了常见拼写错误和黑称defensive: ["常见的错误拼写", "用户起的黑称"]产品优化:从用户吐槽中发现改进点市场洞察。

2501_93332955的博客 781

【锂离子电池力学耦合及相场法模拟技术与应用】

8. 电化学仿真软件的使用与案例分析 (1) 各向异性纳米线锂化应力分析(实例讲解1) (2) 化学反应及死锂现象研究(案例分析2)(3) 锂化循环损伤计算(案例分析3)6. 4. 电池材料的力学与电化学耦合性能分析(1) 耦合效应对电池性能的影响(2) 耦合模型的验证与应。5. 5. 电池颗粒、极片、电芯尺度力-电-化-热多场耦合模型概述力学-7. 颗粒尺度耦合模型在电池失效分析中的应用。2. 2. 电池电极材料的分类与特性。5. (2) 耦合模型的验证与应用。电化学耦合模型与仿真。

weixin_51101456的博客 532

storyboard设置边框颜色_Word教程:只添加一个小小的边框,档次就上升了100倍!...

点击上方[word精品教程]-右上角[...]-[设为星标⭐]即可第一时间获取最新办公资讯日常图文排版的时候,为文档添加一些边框样式进行美化,会使整体排版的质感迅速上升,同时还能“框”住文档内容,让读者的视线聚焦在内容上,避免阅读枯燥。那么,今天在这里给大家分享的Word小技巧,就是如何快速为Word文档添加边框。01添加线型边框(1)点击【设计】-【页面背景】-【页面边框】按钮。(2)...

weixin_39694264的博客 389

杰理蓝牙SPP用户接口详细文档

本文档详细介绍了基于JL701n芯片的蓝牙SPP用户接口实现。主要内容包括:1) 文件结构分析,包含必要的头文件和调试配置;2) 核心数据结构,如全局变量和TWS功能ID定义;3) 五大功能模块实现:数据发送、状态管理、数据接收、TWS支持和初始化清理;4) API接口说明,包括公共接口函数和回调函数;5) 使用教程,涵盖基本流程和高级应用示例。该接口支持虚拟串口连接,实现蓝牙设备间数据传输,特别针对TWS场景进行了优化,提供连接状态管理、数据收发等功能。文档还包含错误处理、重试机制等实用建议,适合蓝牙SP

qq_42014563的博客 1190

按钮边框

border-style: none; 转载于:https://www.cnblogs.com/223zzm/p/11258968.html

weixin_30532837的博客 554

esp8266步进电机驱动控制

blinker控制步进电机起保停,正反转(Arduino uno+esp8266+TB6600驱动器) Arduino uno的板子的程序 esp8266板子接入到Arduino uno的控制引脚上的5,6,7 esp8266程序 //****库***** #define BLINKER_WIFI //官方wifi协议库 #define BLINKER_PRINT Serial //串口协议库 #include <Blinker.h&gt

perseverance51博客 2871

【全覆盖算法】Boustrophedon Cellular Decomposition(BCD)原理及实现

本文先对做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章提示:以下是本篇文章正文内容。

qq_35635374的博客 511

MFC修改button的颜色、背景、边框

MFC的button控件是一个不同于其他控件,其CButtton类是CWnd的一个子类,在修改button的背景、颜色和边框的时候必须自己进行编写一个新的类,如CMyButton。下面是进行背景、颜色、边框修改的步骤: 1.在项目->添加类->CMyButton。这样会自动生成两个文件,一个.CPP文件和一个.h文件。例如CMyButton.cpp和CMyButton.h

那片宁静的港湾 2万+

B3640 T3 句子反转

要求将这些单词倒序输出。而且对于每个单词,如果是小写词,应当转为大写;如果是大写词,应当转为小写;如果是自然数,应该倒转输出。给定一行句子,每个词之间用空格隔开,要么是全小写英文单词,要么是全大写英文单词,要么是自然数。第一次做的时候0分,两个小时没做出来。仅一行,表示程序对句子的处理结果。仅一行,即需要反转的句子。

小前日记 379

微信小程序button边框修改

刚接触微信小程序,今天碰到个button小问题,所以记录分享一下... 结构: &lt;view class='left'&gt; &lt;button&gt;新品&lt;/button&gt; &lt;button&gt;视频&lt;/button&gt; &lt;button&gt;课程&lt;/button&gt; &lt;but

luckybuling 2575

YOLOv12改进策略【卷积层】| SPD-Conv 针对小目标和低分辨率图像的检测任务

SPD-Conv是一种新的 CNN 构建模块,用于替代传统 CNN 架构中使用的步长卷积(strided convolution)和池化(pooling)层,它由空间到深度(Space-to-depth,SPD)层和非步长卷积(non - strided convolution)层组成。

Limiiiing的博客 1788

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

小程序button边框和背景色修改

一:button去掉边框border:none或border:0都无效 因为小程序默认的样式中给button::after{content:""} 自行添加button::after{border:0}去掉button的边框 二:button disable之后背景颜色和字体颜色的值都是默认的。如何修改disable的背景颜色和字体颜色 因为小程序给了button 

sly94的博客 3万+

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

MFC修改button的颜色、背景、边框、对话框标题

MFC的button控件是一个不同于其他控件,其CButtton类是CWnd的一个子类,在修改button的背景、颜色和边框的时候必须自己进行编写一个新的类,如CMyButton。下面是进行背景、颜色、边框修改的步骤: 1.在项目->添加类->CMyButton。这样会自动生成两个文件,一个.CPP文件和一个.h文件。例如CMyButton.cpp和CMyButton.h

u014260683的专栏 494

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

微信小程序 - 修改 button 边框和背景色

为什么80%的码农都做不了架构师?>>> ...

weixin_34378922的博客 1万+

Android开发:修改button的边框和点击改变背景

本文内容 讲解如何修改button的边框,点击button改变背景颜色 打开在res/values目录下的color.xml文件,添加代码: &amp;amp;lt;!-- 绿色 --&amp;amp;gt; &amp;amp;lt;color name=&amp;quot;green&amp;quot;&amp;amp;gt;#008000&amp;amp;lt;/color&amp;amp;gt; &amp;amp;lt;

shakdy的博客 1万+

微信小程序button修改边框样式after

这里写自定义目录标题 在微信小程序中,有些功能必须使用button组件(例如:获取用户手机号 (bindgetphonenumber),微信小程序文档官方传送门),如果使用view等组件,然后设置这个属性,点击是无法触发微信手机号授权的,必须使用button组件 我们接入button后 <button class='sure'>确定</button> .sure{ border-radius: 20px; } 效果如下 可以看到边框有灰色的细线, 当我们把.s

戴戴的博客 2875
上一篇: 修改Button的背景颜色
下一篇: 创建一个类后,jar打包 、keytool 数字签名然后web start 发布(1)
longyi_java
博客等级 码龄20年 24粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址