Example usage for javax.swing JColorChooser setDragEnabled

List of usage examples for javax.swing JColorChooser setDragEnabled

Introduction

In this page you can find the example usage for javax.swing JColorChooser setDragEnabled.

Prototype

@BeanProperty(bound = false, description = "Determines whether automatic drag handling is enabled.")
public void setDragEnabled(boolean b) 

Source Link

Document

Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component.

Usage

From source file:DoubleColor.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Double Color Choosers");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JColorChooser left = new JColorChooser();
    left.setDragEnabled(true);
    frame.add(left, BorderLayout.WEST);
    JColorChooser right = new JColorChooser();
    right.setDragEnabled(true);//w  ww .  j a v  a  2s.  com
    frame.add(right, BorderLayout.EAST);

    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Double Color Choosers");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JColorChooser left = new JColorChooser();
    left.setDragEnabled(true);
    frame.add(left, BorderLayout.WEST);

    JColorChooser right = new JColorChooser();
    right.setDragEnabled(true);//  ww  w. jav a  2s.c  om
    frame.add(right, BorderLayout.EAST);

    frame.pack();
    frame.setVisible(true);

}

From source file:LabelDnD2.java

public LabelDnD2() {
    super(new BorderLayout());

    JColorChooser chooser = new JColorChooser();
    chooser.setDragEnabled(true);

    label = new JLabel("I'm a Label and I accept color!", SwingConstants.LEADING);
    label.setTransferHandler(new TransferHandler("foreground"));

    MouseListener listener = new DragMouseAdapter();
    label.addMouseListener(listener);//from ww w  .j  a va 2 s .  c  o m
    JPanel lpanel = new JPanel(new GridLayout(1, 1));
    TitledBorder t2 = BorderFactory.createTitledBorder("JLabel: drop color onto the label");
    lpanel.add(label);
    lpanel.setBorder(t2);

    add(chooser, BorderLayout.CENTER);
    add(lpanel, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:DragColorDemo.java

public DragColorDemo() {
    super(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    JColorChooser chooser = new JColorChooser();
    chooser.setDragEnabled(true);
    add(chooser, BorderLayout.PAGE_START);

    //Create the color transfer handler.
    colorHandler = new ColorTransferHandler();

    //Create a matrix of 9 buttons.
    JPanel buttonPanel = new JPanel(new GridLayout(3, 3));
    for (int i = 0; i < 9; i++) {
        JButton tmp = new JButton("Button " + i);
        tmp.setTransferHandler(colorHandler);
        buttonPanel.add(tmp);//www.j av  a2  s .  co m
    }
    add(buttonPanel, BorderLayout.CENTER);

    //Create a check box.
    toggleForeground = new JCheckBox("Change the foreground color.");
    toggleForeground.setSelected(true);
    toggleForeground.addActionListener(this);
    JPanel textPanel = new JPanel(new BorderLayout());
    textPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    textPanel.add(toggleForeground, BorderLayout.PAGE_START);

    //Create a label.
    JLabel label = new JLabel("Change the color of any button or this label by dropping a color.");
    label.setTransferHandler(colorHandler);
    label.setOpaque(true); //So the background color can be changed.
    textPanel.add(label, BorderLayout.PAGE_END);
    add(textPanel, BorderLayout.PAGE_END);
}

From source file:DragColorTextFieldDemo.java

public DragColorTextFieldDemo() {
    super(new BorderLayout());
    JTextField textField;/*from ww w.j  a  v  a2  s.c  o m*/

    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    JColorChooser chooser = new JColorChooser();
    chooser.setDragEnabled(true);
    add(chooser, BorderLayout.PAGE_START);

    //Create the color transfer handler.
    colorHandler = new ColorAndTextTransferHandler();

    //Create some text fields.
    JPanel buttonPanel = new JPanel(new GridLayout(3, 1));
    textField = new JTextField("I can accept color/text and drag text.");
    textField.setTransferHandler(colorHandler);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    textField = new JTextField("Me too!");
    textField.setTransferHandler(colorHandler);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    textField = new JTextField("Me three!");
    textField.setTransferHandler(colorHandler);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    add(buttonPanel, BorderLayout.CENTER);
}

From source file:SwingDnDTest.java

public SwingDnDFrame() {
    setTitle("SwingDnDTest");
    JTabbedPane tabbedPane = new JTabbedPane();

    JList list = SampleComponents.list();
    tabbedPane.addTab("List", list);
    JTable table = SampleComponents.table();
    tabbedPane.addTab("Table", table);
    JTree tree = SampleComponents.tree();
    tabbedPane.addTab("Tree", tree);
    JFileChooser fileChooser = new JFileChooser();
    tabbedPane.addTab("File Chooser", fileChooser);
    JColorChooser colorChooser = new JColorChooser();
    tabbedPane.addTab("Color Chooser", colorChooser);

    final JTextArea textArea = new JTextArea(4, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here"));

    JTextField textField = new JTextField("Drag color here");
    textField.setTransferHandler(new TransferHandler("background"));

    tabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            textArea.setText("");
        }/*w w w .  j  a  v a 2s .co  m*/
    });

    tree.setDragEnabled(true);
    table.setDragEnabled(true);
    list.setDragEnabled(true);
    fileChooser.setDragEnabled(true);
    colorChooser.setDragEnabled(true);
    textField.setDragEnabled(true);

    add(tabbedPane, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
    pack();
}