📄 demojcolorchooser.java
字号:
/*
* DemoJColorChooser.java
*
* Created on 2006年3月29日, 上午11:54
*/
package org.netbeans.swing.dialog;
import java.awt.Color;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
/**
*
* @author boyingking
*/
public class DemoJColorChooser extends javax.swing.JFrame {
/** Creates new form DemoJColorChooser */
public DemoJColorChooser() {
initComponents();
ChooseAction caListenr=new ChooseAction(this.jLabelMessage,this.jColorChooserCenter);
this.jColorChooserCenter.getSelectionModel().addChangeListener(caListenr);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jColorChooserCenter = new javax.swing.JColorChooser();
jPanelNorth = new javax.swing.JPanel();
jLabelMessage = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u989c\u8272\u9009\u62e9\u5668\u793a\u4f8b\u7a0b\u5e8f");
jColorChooserCenter.setBorder(javax.swing.BorderFactory.createTitledBorder("\u989c\u8272\u9009\u62e9\u5668"));
getContentPane().add(jColorChooserCenter, java.awt.BorderLayout.CENTER);
jPanelNorth.setBorder(javax.swing.BorderFactory.createTitledBorder("\u663e\u793a\u989c\u8272\u53d8\u5316"));
jLabelMessage.setFont(new java.awt.Font("宋体", 0, 36));
jLabelMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabelMessage.setText("\u6b22\u8fce\u4f7f\u7528\u989c\u8272\u9009\u62e9\u5668");
org.jdesktop.layout.GroupLayout jPanelNorthLayout = new org.jdesktop.layout.GroupLayout(jPanelNorth);
jPanelNorth.setLayout(jPanelNorthLayout);
jPanelNorthLayout.setHorizontalGroup(
jPanelNorthLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jLabelMessage, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
);
jPanelNorthLayout.setVerticalGroup(
jPanelNorthLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabelMessage, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
);
getContentPane().add(jPanelNorth, java.awt.BorderLayout.NORTH);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public void stateChanged(ChangeEvent e)
{
Color newColor=this.jColorChooserCenter.getColor();
this.jLabelMessage.setForeground(newColor);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DemoJColorChooser().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JColorChooser jColorChooserCenter;
private javax.swing.JLabel jLabelMessage;
private javax.swing.JPanel jPanelNorth;
// End of variables declaration//GEN-END:variables
}
class ChooseAction implements javax.swing.event.ChangeListener {
JComponent component;
JColorChooser colorChooser;
public ChooseAction(JComponent component,JColorChooser colorChooser)
{
this.component=component;
this. colorChooser=colorChooser;
}
public void stateChanged(ChangeEvent e) {
Color newColor=this.colorChooser.getColor();
component.setForeground(newColor);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -