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();
分享到:
相关推荐
JColorChooser是Swing库提供的一个颜色选择器组件。它允许用户通过图形界面选择颜色,用于设置和调整应用程序中的颜色值。
Java调色板颜色选择器代码,调用JFrame的构造函数,实例化颜色选择器
主要介绍了Java Swing中的按钮(JButton)、组合框(JComboBox)、下拉列表(JList)和颜色选择器(JColorChooser)组件使用案例,需要的朋友可以参考下
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf 提供...
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf 提供...
JavaTM 编程语言进行服务器端...javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类
javax.swing包提供了Java swing API的类,例如JButton,JTextField,JTextArea,JRadioButton,JCheckbox,JMenu,JColorChooser等。 在Swing组件中,最常见的一个容器就是JFrame,它是一个独立存在的顶级容器(也叫...
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...
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 ...
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf 提供...
swingset3-oracle 运行包, 双击swingset3.bat 运行或者在jar包右键选择java运行. swingset3-src 源码包,感兴趣可以查看示例代码. 包含swing入门组件完整示例, 几乎包含swing所有组件介绍 ,可以带你入门了解swing的...
javax.swing.colorchooser 包含供 JColorChooser 组件使用的类和接口。 javax.swing.event 供 Swing 组件触发的事件使用。 javax.swing.filechooser 包含 JFileChooser 组件使用的类和接口。 javax.swing.plaf ...
Here is a colour selection button class:shows current selected coloropens a JColorChooser dialog when pressedfires events when a color is selected
Swing组件(javax.swing.-) 面板:JPanel 标签化窗格:JTabbedPane 拆分窗格:JSplitPane 滚动窗格:JScrollPane 工具栏:JToolBar 桌面窗格:JDesktopPane 内部框架:JInternalFrame 分层窗格:JLayeredPane ...
import javax.swing.JColorChooser; public class Jishiben extends Frame implements ActionListener { MenuBar menuBar; //定义菜单条 TextArea textArea=new TextArea(20,50);//定义文本区 public OptionOfFile...