本文整理汇总了Java中javax.swing.JColorChooser.setPreviewPanel方法的典型用法代码示例。如果您正苦于以下问题:Java JColorChooser.setPreviewPanel方法的具体用法?Java JColorChooser.setPreviewPanel怎么用?Java JColorChooser.setPreviewPanel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JColorChooser
的用法示例。
在下文中一共展示了JColorChooser.setPreviewPanel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showDialog
import javax.swing.JColorChooser; //导入方法依赖的package包/类
private Color showDialog(Component component, String title, Color initialColor) throws HeadlessException {
final JColorChooser chooser = new JColorChooser(initialColor != null ? initialColor : Color.white);
// configuring color chooser panel
chooser.setPreviewPanel(new JPanel());
if (colorChoosers != null) {
chooser.setChooserPanels(colorChoosers);
} else {
chooser.removeChooserPanel(chooser.getChooserPanels()[0]);
chooser.removeChooserPanel(chooser.getChooserPanels()[1]);
}
// creating dialog
ColorTracker ok = new ColorTracker(chooser);
JDialog dialog = JColorChooser.createDialog(component, title, true, chooser, ok, null);
dialog.setVisible(true); // blocks until user brings dialog down...
return ok.getColor();
}
示例2: test
import javax.swing.JColorChooser; //导入方法依赖的package包/类
private static void test(Color[] colors) {
JLabel label = new JLabel("Preview Panel"); // NON-NLS: simple label
JColorChooser chooser = new JColorChooser();
chooser.setPreviewPanel(label);
float[] hsb = new float[3];
for (int i = 0; i < colors.length; i++) {
Color color = colors[i];
// Make sure sure that there wasn't a regression
// in java.awt.Color and the conversion methods
Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
if (!color.equals(Color.getHSBColor(hsb[0], hsb[1], hsb[2]))) {
throw new Error("color conversion is failed");
}
// 4193384 regression test
if (!color.equals(new JColorChooser(color).getColor())) {
throw new Error("constructor sets incorrect initial color");
}
// 4200976 regression test
chooser.setColor(color);
if (!color.equals(label.getForeground())) {
throw new Error("a custom preview panel doesn't handle colors");
}
}
}
示例3: main
import javax.swing.JColorChooser; //导入方法依赖的package包/类
public static void main(String[] args) {
JColorChooser chooser = new JColorChooser();
if (null == chooser.getPreviewPanel()) {
throw new Error("Failed: getPreviewPanel() returned null");
}
JButton button = new JButton("Color"); // NON-NLS: simple label
chooser.setPreviewPanel(button);
if (button != chooser.getPreviewPanel()) {
throw new Error("Failed in setPreviewPanel()");
}
}
示例4: init
import javax.swing.JColorChooser; //导入方法依赖的package包/类
public void init() {
JColorChooser chooser = new JColorChooser();
chooser.setPreviewPanel(new JLabel("Text Preview Panel"));
getContentPane().add(chooser);
}
示例5: init
import javax.swing.JColorChooser; //导入方法依赖的package包/类
public void init() {
JColorChooser chooser = new JColorChooser();
chooser.setPreviewPanel(new JPanel());
getContentPane().add(chooser);
}