您的位置:

java按钮颜色设置问题,java设置按钮背景颜色

本文目录一览:

java中如何设置按钮文字的大小、颜色和字体?

submit=newJButton("登陆");\x0d\x0a\x0d\x0asubmit.setFont(newFont("宋体",Font.PLAIN,16));\x0d\x0a三个参数分别表示:字体,样式(粗体,斜体等),字号\x0d\x0a\x0d\x0asubmit.setForeground(Color.RED);\x0d\x0a这个表示给组件上的文字设置颜色Color.RED表示红色\x0d\x0a当然你也可以自己给RGB的值比如submit.setForeground(newColor(215,215,200));\x0d\x0a\x0d\x0aJLabel组件支持HTML标记代码\x0d\x0ainfoLab=newJLabel("用户登陆系统",JLabel.CENTER);\x0d\x0a\x0d\x0a*注意:地址要单引号引起来。这个表示给用户登录系统几个字增加超链接\x0d\x0ainfoLab.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));\x0d\x0a\x0d\x0a这个表示给这个文字添加鼠标样式,当鼠标移动到文字上,鼠标变成手型

如何改变java按钮中的颜色?

setForeground() 设置前景/字体颜色

setBackground() 设置背景颜色

具体实现:(假设按钮名称为:button)

设置红字:

button.setForeground(Color.red);

设置黑色背影:

button.setBackground(Color.black);

JAVA中的JButton的背景颜色设置问题。用的是MacBook pro,用eclipse写的。

mac os 默认的border是aqua border(look and feel设置),这个border是一个灰白色填充外加灰色边界的矩形,在初始化button的时候默认是显示border的,所以你会发现这个aqua border layer把你的button覆盖了。此时button上的图层从底向上分别是backgroundforegroundborder layer.所以你看到的灰白色其实是你的默认border。

设置button颜色的解决有两种,你可以设置background颜色,然后设置button foreground透明,border层不显示。

button.setBackground(Color.RED);//设置background颜色

button.setOpaque(true); //foreground设置透明

button.setBorderPainted(false); //最后显示红色

或者设置foreground颜色,这样会把background盖住,然后设置border层不显示。

button.setBackGround(Color.RED); // 随便设,反正会被盖

button.setForeGround(Color.BLUE); //盖住背景色

button.setBorderPainted(false); //最后显示蓝色

另外,你也可以自己设置一个lineBorder代替mac os默认的aqua border。

originBorder=BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1);//这个是windows的默认border

button.setForeGround(Color.BLUE);

button.setBorder(originBorder);//最后会显示一个蓝色,带浅灰边框的button

这个问题在window是不存在的,因为window的默认border是swing border,是无填充透明边界,不会盖住foreground layer和background layer。所以你在windows情况下只要设置好前景色背景色的覆盖关系就行了(比如设置button透明并设置背景色,或者直接设置前景色)。

覆盖关系,覆盖关系,覆盖关系。重说三。

另外mac第三种解决方式:自己网上关键字查找mac java swing look and feel,下载对应的包加入自己的库,然后在swing的window或者panel主函数第一句先:

try{

UIManager.setLookAndFeel(#这里是对应的look and feel包名字#);

}catch(Exception e){e.printStackTrace()}

不过我不推荐这个做法,因为换地方的时候没有库会异常,然后使用默认的lookandfeel。

java改变按钮颜色

为yellow、blue、red3个按钮添加actionlistener,当按钮点击时执行setBackground(backgroundColor),同时执行 按钮.setBackground(backgroundColor)即可,比如:

JButton btnYellow = null;

JButton btnBlue = null;

JButton btnRed = null;

btnYellow.setActionCommand("yellow");

btnBlue.setActionCommand("blue");

btnRed.setActionCommand("red");

public void actionPerformed(ActionEvent e) {

String command = event.getActionCommand();

if( "yellow".equals(command) ){

setBackground(Color.yellow);

btnYellow.setBackground(Color.yellow);

}else if( "blue".equals(command) ){

setBackground(Color.blue);

btnBlue.setBackground(Color.blue);

}else if( "red".equals(command) ){

setBackground(Color.red);

btnRed.setBackground(Color.red);

}

}

写出了部分代码

java按钮颜色设置问题,java设置按钮背景颜色

2022-11-21
java点击按钮后按钮变颜色(java按钮点击改变颜色)

2022-11-11
java设置用户界面背景颜色,java设置用户界面背景颜色不

2022-11-22
java按钮效果的设置(java按钮实现功能)

2022-11-09
js颜色color设置,js怎么设置背景颜色

2022-11-23
怎么使jsp页面背景颜色的代码,jsp怎样设置页面的颜色

本文目录一览: 1、如何给jsp页面添加背景图片 2、如何将first.jsp显示的页面底色修改为红色 3、jsp怎样设置网页背景颜色 4、jsp中js实现点击按钮更改背景图片代码怎么写? 如何给js

2023-12-08
java颜色,java颜色代码怎么用

2023-01-07
pycharm背景颜色设置

2023-05-10
Python Tkinter窗口背景颜色设置指南

2023-05-13
jsp页面背景颜色设置,jsp背景颜色怎么设置

2023-01-09
java窗体按钮,java窗体按钮事件

2023-01-06
solidworks界面背景颜色设置,solidworks工

2023-01-07
when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: ${item.id} [in template "article/detail/index.ftl" at line 48, column 106] ---- Java stack trace (for programmers): ---- freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:481) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:401) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:370) at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:104) at freemarker.core.DollarVariable.accept(DollarVariable.java:63) at freemarker.core.Environment.visit(Environment.java:371) at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321) at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271) at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244) at freemarker.core.Environment.visitIteratorBlock(Environment.java:645) at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108) at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94) at freemarker.core.Environment.visit(Environment.java:335) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.process(Environment.java:314) at freemarker.template.Template.process(Template.java:383) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:332) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:266) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:220) at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:181) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1431) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1106) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at com.software.filter.HttpSpiderIdentifyFilter.doFilter(HttpSpiderIdentifyFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) at java.base/java.lang.VirtualThread.run(VirtualThread.java:309)