`
Hode
  • 浏览: 26979 次
  • 性别: Icon_minigender_2
  • 来自: 成都
社区版块
存档分类
最新评论

Java Swing学习笔记4_JColorChooser

阅读更多
JColorChooser

banner = new JLabel("Welcome,please select the color", JLabel.CENTER);
		banner.setForeground(Color.yellow);
		banner.setAutoscrolls(true);
		banner.setFont(new Font("SansSerif", Font.BOLD, 24));
		banner.setOpaque(true);
		banner.setBackground(Color.blue);
        banner.setPreferredSize(new Dimension(100, 65));

		JPanel bannerPanel = new JPanel();
		bannerPanel.setLayout(new BorderLayout());
		bannerPanel.add(banner);

		chooser = new JColorChooser();
		// custom your color chooser,so custom the abstractcolorchooserpanel
		AbstractColorChooserPanel panels[] = { new CrayonPanel() };
		chooser.setChooserPanels(panels);
		chooser.setColor(banner.getForeground());
        
		chooser.getSelectionModel().addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent e) {
				banner.setForeground(chooser.getColor());
			}
		});

		// pagestart,pageend,linestart,lineend,center(like
		// north,south,west,east,center),the former is recommonded;
		add(bannerPanel, BorderLayout.PAGE_START);
		add(chooser, BorderLayout.PAGE_END);


AbstractColorChooserPanel

如果要实现自定义的colorchooser,则只是需要继承该抽象类而已。
   /**
      * Invoked automatically when the model's state changes.
      * It is also called by <code>installChooserPanel</code> to allow
      * you to set up the initial state of your chooser.
      * Override this method to update your <code>ChooserPanel</code>.
      */
    public abstract void updateChooser();

    /**
     * Builds a new chooser panel.
     */
    protected abstract void buildChooser();

    /**
     * Returns a string containing the display name of the panel.
     * @return the name of the display panel
     */
    public abstract String getDisplayName();

 /**
     * Returns the small display icon for the panel.
     * @return the small display icon
     */
    public abstract Icon getSmallDisplayIcon();

    /**
     * Returns the large display icon for the panel.
     * @return the large display icon
     */
    public abstract Icon getLargeDisplayIcon();


分享到:
评论

相关推荐

    java swing-JColorChooser的使用

    JColorChooser是Swing库提供的一个颜色选择器组件。它允许用户通过图形界面选择颜色,用于设置和调整应用程序中的颜色值。

    JColorChooser_java_

    Java调色板颜色选择器代码,调用JFrame的构造函数,实例化颜色选择器

    Java Swing中的JButton、JComboBox、JList和JColorChooser组件使用案例

    主要介绍了Java Swing中的按钮(JButton)、组合框(JComboBox)、下拉列表(JList)和颜色选择器(JColorChooser)组件使用案例,需要的朋友可以参考下

    JAVA_API1.6文档(中文)

    javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...

    Java 1.6 API 中文 New

    javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf 提供...

    [Java参考文档].JDK_API 1.6

    javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf 提供...

    2010年11月6日招聘会参会企业名单.xls

    JavaTM 编程语言进行服务器端...javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类

    实验九 图形用户界面GUI(文档中包含可执行源码)

    javax.swing包提供了Java swing API的类,例如JButton,JTextField,JTextArea,JRadioButton,JCheckbox,JMenu,JColorChooser等。 在Swing组件中,最常见的一个容器就是JFrame,它是一个独立存在的顶级容器(也叫...

    java jdk-api-1.6 中文 chmd

    javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...

    java7帮助文档

    Toolkits AWT Swing Java 2D Accessibility Drag n Drop Input Methods Image I/O Print Service Sound Java SE API Integration Libraries IDL JDBC JNDI RMI RMI-IIOP Scripting Other Base Libraries ...

    JavaAPI1.6中文chm文档 part1

    javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...

    java api最新7.0

    javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf 提供...

    oracle jdk自带swing 代码示例swingset3

    swingset3-oracle 运行包, 双击swingset3.bat 运行或者在jar包右键选择java运行. swingset3-src 源码包,感兴趣可以查看示例代码. 包含swing入门组件完整示例, 几乎包含swing所有组件介绍 ,可以带你入门了解swing的...

    JavaAPI中文chm文档 part2

    javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...

    ColoredPrinter.java.zip_Java编程_Java_

    Here is a colour selection button class:shows current selected coloropens a JColorChooser dialog when pressedfires events when a color is selected

    Swing组件下载(常用组件)

    Swing组件(javax.swing.-) 面板:JPanel 标签化窗格:JTabbedPane 拆分窗格:JSplitPane 滚动窗格:JScrollPane 工具栏:JToolBar 桌面窗格:JDesktopPane 内部框架:JInternalFrame 分层窗格:JLayeredPane ...

    用java做的记事本

    import javax.swing.JColorChooser; public class Jishiben extends Frame implements ActionListener { MenuBar menuBar; //定义菜单条 TextArea textArea=new TextArea(20,50);//定义文本区 public OptionOfFile...

Global site tag (gtag.js) - Google Analytics