JLabel默认是透明的,所以JLabel设置背景色setBackground之前要setOpaque(true);

news/2025/2/7 11:09:09/

JLabel默认是透明的,所以JLabel设置背景色setBackground之前要setOpaque(true);

将不透明设为true,再setBackground
jlabel.setOpaque(true); jlabel.setBackground(new Color(0, 0, 0, 100));

//将不透明设为true,再setBackgroundjlabel.setOpaque(true); jlabel.setBackground(new Color(0, 0, 0, 100));
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.*;
import javax.swing.*;public class JLabel默认是透明的_所以JLabel设置背景色setBackground之前要setOpaque为true {public static void main(String...arguments)throws Exception{JFrame frame = new JFrame(Thread.currentThread().getStackTrace()[1].getClassName());frame.addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent windowEvent) {System.out.println(windowEvent);System.exit(0);}});frame.setBounds(100, 100, 1024, 768);JLabel jlabel = new JLabel("""<html><head></head><body><div style='background:rgba(100,100,255,0.5); text-align:center;'>JLabel默认是透明的_所以JLabel设置背景色setBackground之前要setOpaque为true<br/>//将不透明设为true,再setBackground<br/>label.setOpaque(true); jlabel.setBackground(new Color(0, 0, 0, 200));JLabel中的html的背景色不会覆盖整个JLable, html的background在JLabel的background之上</div></body></html>""");frame.add(jlabel);//将不透明设为true,再setBackgroundjlabel.setOpaque(true); jlabel.setBackground(new Color(0, 0, 0, 100));frame.setVisible(true);}}

在这里插入图片描述


http://www.ppmy.cn/news/100413.html

相关文章

【技术解决方案】企业如何从SpringBoot应用平滑迁移到云原生K8s平台

文章目录 在K8S上部署Spring Cloud Alibaba在Kubernetes上部署Spring Cloud Kubernetes在Kubernetes上部署Spring Boot应用方案对比分析拥抱Service Mesh关于DevopsServerless最佳实践 好久不见了&#xff0c;小伙伴们&#xff0c;你们最近还好吗&#xff1f;有没有想我&#x…

1、Vue.js---Vue核心

目录 Vue是什么 什么是渐进式&#xff1a; Vue 的特点 与其它 JS 框架的关联 Vue 周边库 搭建Vue开发环境&#xff08;2种方式&#xff09; 1、直接用 2、NPM Hello小案例 小结&#xff1a; 模板语法 代码 小结&#xff1a; 数据绑定 代码&#xff1a; 小结&…

JavaScript6

一、概念 ES6是JavaScript语言的标准。 新特性&#xff1a;let和const命令、变量的解构赋值、字符串函数对象数组等扩展。 环境准备&#xff1a;需要安装NodeJs。 二、新特性 1、let let命令用来声明变量。他的用法类似var&#xff0c;但所声明的变量&#xff0c;只在let命令…

C++11 addressof()函数(模板函数)(在对象重载了取地址运算符时,获取对象真实地址)

文章目录 addressof模板函数在对象重载了取地址运算符&#xff0c;addressof函数模板就能发挥作用 addressof模板函数 C中的addressof函数是一个模板函数&#xff0c;定义在头文件<memory>中。它的作用是获取一个对象的地址&#xff0c;与C中的取地址符&类似&#x…

PAT A1160 Forever

1160 Forever 分数 20 作者 陈越 单位 浙江大学 "Forever number" is a positive integer A with K digits, satisfying the following constrains: the sum of all the digits of A is m;the sum of all the digits of A1 is n; andthe greatest common diviso…

ISP:接口隔离原则

系列文章目录 C高性能优化编程系列 深入理解设计原则系列 深入理解设计模式系列 高级C并发线程编程 LSP&#xff1a;接口隔离原则 系列文章目录1、接口隔离原则的定义和解读如何判断一个接口是否符合接口隔离原则&#xff1f;小结 1、接口隔离原则的定义和解读 Robert Marti…

【Python】Python中列表的操作方法

Python中列表的操作 Python中的列表是用来存储一系列元素的有序集合。列表是可变的&#xff0c;这意味着我们可以添加、删除或修改列表中的元素。本文将介绍Python中列表的基本操作&#xff0c;包括创建列表、访问列表元素、添加元素、删除元素和列表切片, 反转等。 访问列表…

queue的模拟实现

前言 queue作为STL中的容器适配器&#xff0c;在底层是通过一系列的成员函数来调用其他容器的接口实现的 &#xff0c;它其实就是将其他模板容器进行封装从而实现它&#xff0c;先进先出的特性的。 目录 1.queue的接口说明 2.queue的模拟实现 2.1模拟实现代码 2.1测试代码 …