public ColorChooserDemo() { super(new BorderLayout()); // 设置一个标签,做广告的。也用来显示用户选择的颜色。 banner = new JLabel("欢迎使用颜色选择器!", JLabel.CENTER); banner.setForeground(Color.yellow); banner.setBackground(Color.blue); banner.setOpaque(true); banner.setFont(new Font("SansSerif", Font.BOLD, 24)); banner.setPreferredSize(new Dimension(100, 65)); JPanel bannerPanel = new JPanel(new BorderLayout()); bannerPanel.add(banner, BorderLayout.CENTER); bannerPanel.setBorder(BorderFactory.createTitledBorder("广告")); // 设置选择颜色选择器 tcc = new JColorChooser(banner.getForeground()); // 设置初始颜色 tcc.getSelectionModel().addChangeListener(this); // 给所有模式添加监听 tcc.setBorder(BorderFactory.createTitledBorder("选择颜色")); add(bannerPanel, BorderLayout.CENTER); add(tcc, BorderLayout.PAGE_END); }
public PaletteView(AnimatorModel aModel) { super(); this.setLayout(new GridBagLayout()); this.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); tcc = new JColorChooser(); tcc.setBorder(BorderFactory.createTitledBorder("Choose Draw Color")); choose = new JButton("Picker"); choose.setBorderPainted(false); choose.setOpaque(true); choose.setFocusable(false); choose.setBackground(Color.GRAY); small = new JRadioButton("sm"); small.setFocusable(false); medium = new JRadioButton("med"); medium.setSelected(true); small.setFocusable(false); large = new JRadioButton("big"); small.setFocusable(false); black = new JButton(); black.setBackground(Color.BLACK); black.setBorderPainted(false); black.setOpaque(true); black.setFocusable(false); blue = new JButton(); blue.setBackground(new Color(51, 204, 255)); blue.setBorderPainted(false); blue.setOpaque(true); blue.setFocusable(false); green = new JButton(); green.setBackground(new Color(51, 255, 102)); green.setBorderPainted(false); green.setOpaque(true); green.setFocusable(false); violet = new JButton(); violet.setBackground(new Color(204, 51, 255)); violet.setBorderPainted(false); violet.setOpaque(true); violet.setFocusable(false); pink = new JButton(); pink.setBackground(new Color(249, 119, 214)); pink.setBorderPainted(false); pink.setOpaque(true); pink.setFocusable(false); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 0; constraints.ipady = 18; this.add(black, constraints); constraints.gridy = 1; this.add(blue, constraints); constraints.gridy = 2; this.add(green, constraints); constraints.gridy = 3; this.add(violet, constraints); constraints.gridy = 4; this.add(pink, constraints); constraints.gridy = 5; this.add(choose, constraints); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.setBorder(BorderFactory.createTitledBorder("Stroke")); p.add(small); p.add(medium); p.add(large); constraints.gridy = 6; this.add(p, constraints); this.registerControllers(); model = aModel; this.model.addView(this); }
public DefaultDnDSupport() { JFrame fen = new JFrame("DnD et CCP"); fen.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER)); fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Panel gauche JPanel panelgauche = new JPanel(); panelgauche.setLayout(new BoxLayout(panelgauche, BoxLayout.Y_AXIS)); // JTextField JTextField textField = new JTextField(10); textField.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JTextField"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); textField.setDragEnabled(true); // JPasswordField JPasswordField passwordField = new JPasswordField(10); passwordField.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JPasswordField"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); passwordField.setDragEnabled(true); // JFormattedTextField JFormattedTextField ftf = new JFormattedTextField("Universite de Lille 1"); ftf.setFont(new Font("Courier", Font.ITALIC, 12)); ftf.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JFormattedTextField"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); ftf.setDragEnabled(true); // JTextArea JTextArea jta = new JTextArea("Master 1 informatique"); jta.setFont(new Font("Arial", Font.BOLD, 12)); jta.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JTextArea"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); jta.setDragEnabled(true); // JEditorPane JEditorPane editorPane = createEditorPane(); editorPane.setDragEnabled(true); JScrollPane editorScrollPane = new JScrollPane(editorPane); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JEditorPane"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // JColorChooser JColorChooser cc = new JColorChooser(); cc.setDragEnabled(true); cc.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JColorChooser"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // Panel droit JPanel paneldroit = new JPanel(); paneldroit.setLayout(new BoxLayout(paneldroit, BoxLayout.Y_AXIS)); // JList String[] data = { "AAC", "AEV", "ANG", "ASE", "COA", "PJE", "CAR", "PJI", "AeA", "BDA", "CALP", "FDD", "HECI", "IHM", "M3DS", "PAC", "PPD", "RdF", "SVL", "TI" }; JList liste = new JList(data); JScrollPane jscrollListe = new JScrollPane(liste); jscrollListe.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JList"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // liste.setDragEnabled(true); // JTree DefaultMutableTreeNode m1 = new DefaultMutableTreeNode("M1"); DefaultMutableTreeNode s1 = new DefaultMutableTreeNode("S1"); m1.add(s1); s1.add(new DefaultMutableTreeNode("AAC")); s1.add(new DefaultMutableTreeNode("AEV")); s1.add(new DefaultMutableTreeNode("ANG")); s1.add(new DefaultMutableTreeNode("ASE")); s1.add(new DefaultMutableTreeNode("COA")); s1.add(new DefaultMutableTreeNode("PJE")); DefaultMutableTreeNode s2 = new DefaultMutableTreeNode("S2"); m1.add(s2); s2.add(new DefaultMutableTreeNode("CAR")); s2.add(new DefaultMutableTreeNode("PJI")); s2.add(new DefaultMutableTreeNode("AeA")); s2.add(new DefaultMutableTreeNode("BDA")); s2.add(new DefaultMutableTreeNode("CALP")); s2.add(new DefaultMutableTreeNode("FDD")); s2.add(new DefaultMutableTreeNode("HECI")); s2.add(new DefaultMutableTreeNode("IHM")); s2.add(new DefaultMutableTreeNode("M3DS")); s2.add(new DefaultMutableTreeNode("PAC")); s2.add(new DefaultMutableTreeNode("PPD")); s2.add(new DefaultMutableTreeNode("RdF")); s2.add(new DefaultMutableTreeNode("SVL")); s2.add(new DefaultMutableTreeNode("TI")); JTree tree = new JTree(m1); // tree.setDragEnabled(true); JScrollPane jscrollTree = new JScrollPane(tree); jscrollTree.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JTree"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); jscrollTree.setPreferredSize(new Dimension(200, 200)); // JTable String[] columnNames = {"S1", "S2"}; Object[][] data2 = { {"AAC", "CAR"}, {"AEV", "PJI"}, {"ANG", "AeA"}, {"ASE", "BDA"}, {"COA", "CALP"}, {"PJE", "FDD"}, {"", "HECI"}, {"", "IHM"}, {"", "M3DS"}, {"", "PAC"}, {"", "PPD"}, {"", "RdF"}, {"", "SVL"}, {"", "TI"} }; JTable table = new JTable(data2, columnNames); JScrollPane scrollPaneTable = new JScrollPane(table); table.setDragEnabled(true); // JFileChooser JFileChooser fc = new JFileChooser(); fc.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JFileChooser"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); fc.setDragEnabled(true); panelgauche.add(textField); panelgauche.add(passwordField); panelgauche.add(ftf); panelgauche.add(jta); panelgauche.add(cc); panelgauche.add(editorScrollPane); fen.getContentPane().add(panelgauche); paneldroit.add(fc); paneldroit.add(jscrollListe); paneldroit.add(jscrollTree); paneldroit.add(scrollPaneTable); fen.getContentPane().add(paneldroit); fen.pack(); fen.setVisible(true); }