java使用顏色選擇器示例分享
package com.liuxing.test;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ColorChooser extends JFrame {
private JLabel sampleText = new JLabel("Label");
private JButton chooseButton = new JButton("Choose Color");
public static void main(String[] args) {
new ColorChooser();
}
public ColorChooser() {
this.setSize(300, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 = new JPanel();
sampleText.setBackground(null);
panel1.add(sampleText);
chooseButton.addActionListener(new ButtonListener());
panel1.add(chooseButton);
this.add(panel1);
this.setVisible(true);
}
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Color c = JColorChooser.showDialog(null, "Choose a Color", sampleText.getForeground());
if (c != null)
sampleText.setForeground(c);
}
}
}
相關(guān)文章
Mybatis-Plus處理Mysql?Json類型字段的詳細(xì)教程
這篇文章主要給大家介紹了關(guān)于Mybatis-Plus處理Mysql?Json類型字段的詳細(xì)教程,Mybatis-Plus可以很方便地處理JSON字段,在實(shí)體類中可以使用@JSONField注解來標(biāo)記JSON字段,同時(shí)在mapper.xml中使用json函數(shù)來操作JSON字段,需要的朋友可以參考下2024-01-01聊聊spring @Transactional 事務(wù)無法使用的可能原因
這篇文章主要介紹了spring @Transactional 事務(wù)無法使用的可能原因,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07Spring Boot如何使用httpcomponents實(shí)現(xiàn)http請(qǐng)求
這篇文章主要介紹了Spring Boot使用httpcomponents實(shí)現(xiàn)http請(qǐng)求的示例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07詳解Java實(shí)現(xiàn)緩存(LRU,FIFO)
本篇文章主要介紹了詳解Java實(shí)現(xiàn)緩存(LRU,FIFO) ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04EventBus與Spring Event區(qū)別詳解(EventBus 事件機(jī)制,Spring Event事件機(jī)制)
這篇文章主要介紹了EventBus與Spring Event區(qū)別,需要的朋友可以參考下2020-02-02SpringBoot2.4.2下使用Redis配置Lettuce的示例
這篇文章主要介紹了SpringBoot2.4.2下使用Redis配置Lettuce,Springboot2.4.2下默認(rèn)使用的就是Lettuce而不是Jedis因此無需在依賴進(jìn)行排除Jedis,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2022-01-01Java詳細(xì)分析sleep和wait方法有哪些區(qū)別
這篇文章主要介紹了Java中wait與sleep的講解(wait有參及無參區(qū)別),通過代碼介紹了wait()?與wait(?long?timeout?)?區(qū)別,wait(0)?與?sleep(0)區(qū)別,需要的朋友可以參考下2022-04-04詳解Mybatis-plus(MP)中CRUD操作保姆級(jí)筆記
本文主要介紹了Mybatis-plus(MP)中CRUD操作保姆級(jí)筆記,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11