?? e878. customizing the preview panel of a jcolorchooser dialog.txt
字號:
The preview panel shows the selected color in a particular context. The default preview panel colors some text with the selected color.
It may be desirable to change the preview panel to a more relevant setting. For example, if the color chooser is used to color an image, a miniature version of the image can be shown in the preview panel.
JColorChooser chooser = new JColorChooser();
chooser.setPreviewPanel(new MyPreviewPanel(chooser));
// This preview panel simply displays the currently selected color.
public class MyPreviewPanel extends JComponent {
// The currently selected color
Color curColor;
public MyPreviewPanel(JColorChooser chooser) {
// Initialize the currently selected color
curColor = chooser.getColor();
// Add listener on model to detect changes to selected color
ColorSelectionModel model = chooser.getSelectionModel();
model.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
ColorSelectionModel model = (ColorSelectionModel)evt.getSource();
// Get the new color value
curColor = model.getSelectedColor();
}
}) ;
// Set a preferred size
setPreferredSize(new Dimension(50, 50));
}
// Paint current color
public void paint(Graphics g) {
g.setColor(curColor);
g.fillRect(0, 0, getWidth()-1, getHeight()-1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -