JTextField keyEvent consume()

This question is related to the keyEvent-architecture.
The JTextField (or any JTextComponent for that matter) is designed to use the keyEvents but NOT consume it. Which means the JTextField modifies its internal Document-model and leaves the keyEvent to propagate further for any body (parent-component etc.) to use it.
I dont really understand why the design leaves that event to be used by anybody with key-mapping for that keyEvent !?!
In the specific problem that I have, I am putting JTextField in MainFrame which also has zoomIn/zoomOut Menu-actions attached to Minus(-) and Plus(+) keys respectively.
What I notice is whenever I type, Minus(-) in JTextField, zoomIn is invoked !!
Well, I was able to prevent that from happening by attaching a keyListener to my JTextField whose ONLY JOB is to consume() ALL keyevents. (ConsumeAllKeysListener)
This preety much solves my problem. But I would like to know, is this the correct way to prevent STRAY keyEvent propagation ?
Also until now, I thought that the JTextField uses InputMap/ActionMap to append all the regular keys that are typed. This assumption is does not seem to be true since even when I consume all the keyEvents by attaching the "ConsumeAllKeysListener" the keys actually end up being typed in the JTextField (although that is what I want).
But, this behaviour makes me think that JTextField has its Document/model setup as keyListener to itself rather that handling the keyEvent using InputMap/ActionMap. Is this true ?
Hope I am not confusing the matter !?!
Thanks in anticipation,
-sharad

As mentioned above the correct way to do this is to use a Document to edit any characters as they are typed. The reason for this is that this approach will work whether data is 'typed' or 'pasted' into the text field. Check out this section from the Swing tutorial for more information on Documents and examples:
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html#validation
I do not recommend using a KeyListener, but here is the reason why it doesn't work.
Three events are generated every time you type a character into a text field:
1) key pressed
2) key typed
3) key released
The key typed event seems to be the important event for adding text to the text field so you could add code in the keyTyped(..) method:
if (e.getKeyChar() == ',')
    e.consume();

Similar Messages

  • KeyEvent consume

    Hi!,
    It's me again, he9x, ahm having progress with my testlayout/calculator...just having problems with the KeyEvent consume method. I'm trying to limit the entry of DOT ex. 3.23 - allowed
    .45 - allowed
    .46.67 or 4.566.67 - not allowed
    Here's my code that handles it, but the problem is when I try to enter 4.56. upon entering the second period my message pops up and the second period is displayed. even though it pass through the event.consume method. should it not display the period? Thank you so much for your help!
    here's my code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TestLayout extends JFrame{
        //private JTextField text;   
        private IntegerTextField text;
        private JButton btnOne, btnTwo, btnThree, btnFour, btnFive,
                        btnSix, btnSeven, btnEight, btnNine, btnZero,
                        btnAdd, btnSubtract, btnMultiply, btnDivide,
                        btnSqrRt, btnModulo, btnBack, btnCE;
        private JPanel northPanel, centerPanel, southPanel;
        private int textNum;
        public TestLayout(){
           Container container = getContentPane();
           //text = new JTextField(14);
           //text = new TestLayout().new IntegerTextField(14);
           text = new IntegerTextField(14);
           text.setPreferredSize(new Dimension(255, 20));
           text.setHorizontalAlignment(JTextField.TRAILING);
           text.addActionListener(new ActionHandler());
           northPanel = new JPanel();
           northPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
           northPanel.add(text);
           container.add(northPanel, BorderLayout.NORTH);
           centerPanel = new JPanel();
           centerPanel.setLayout(new GridLayout(4, 4));
           btnOne = new JButton("1");
           btnTwo = new JButton("2");
           btnThree = new JButton("3");
           btnFour = new JButton("4");
           btnFive = new JButton("5");
           btnSix = new JButton("6");
           btnSeven = new JButton("7");
           btnEight = new JButton("8");
           btnNine = new JButton("9");
           btnZero = new JButton("0");
           btnMultiply = new JButton("*");
           btnDivide = new JButton("/");
           btnAdd = new JButton("+");
           btnSubtract = new JButton("-");
           btnSqrRt = new JButton("sqrt");
           btnModulo = new JButton("%");
           centerPanel.add(btnOne);
           centerPanel.add(btnTwo);
           centerPanel.add(btnThree);
           centerPanel.add(btnFour);      
           centerPanel.add(btnFive);
           centerPanel.add(btnSix);
           centerPanel.add(btnSeven);
           centerPanel.add(btnEight);      
           centerPanel.add(btnNine);
           centerPanel.add(btnZero);
           centerPanel.add(btnMultiply);
           centerPanel.add(btnDivide);      
           centerPanel.add(btnAdd);
           centerPanel.add(btnSubtract);
           centerPanel.add(btnSqrRt);
           centerPanel.add(btnModulo);      
           container.add(centerPanel, BorderLayout.CENTER);
           southPanel = new JPanel();
           southPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
           btnBack = new JButton("Backspace");
           btnCE   = new JButton("   CE    ");
           southPanel.add(btnBack);
           southPanel.add(btnCE);
           container.add(southPanel, BorderLayout.SOUTH);
           setSize(275, 250);
           setVisible(true);
        private class ActionHandler implements ActionListener {
           public void actionPerformed(ActionEvent event){
               if(event.getSource() == text)
                  computeText();
        private void computeText(){
           int num = Integer.parseInt(text.getText()) -1;
           text.setText(String.valueOf(num));
        private class IntegerTextField extends JTextField{
           //final static String badchars = "`~!@#$%^&*()_+=\\|\"':;?/>.<, ";
           final static String badchars = "`~!@#$%^&*()_+=\\|\"':;?/><, ";
           public IntegerTextField(int columns){
                  super(columns);
           public void processKeyEvent(KeyEvent event){
                  char c = event.getKeyChar();
                if ( (Character.isLetter(c) && !event.isAltDown())
                     || badchars.indexOf(c) > -1) {
                     event.consume();
                     return;
                if ( (c == '-') && getDocument().getLength() > 0 ){
                     event.consume();}
                else{
                     super.processKeyEvent(event);
                if ( (c == '.') && (getText().lastIndexOf(c) != getText().indexOf(c)) ){
                     event.consume();
                     String temp = String.valueOf(c) + String.valueOf(getText().lastIndexOf(c));
                     if (event.isConsumed()) JOptionPane.showMessageDialog(null, temp);
                }else{
                     super.processKeyEvent(event);
        public static void main(String args[]){
           TestLayout test = new TestLayout();
           //test = new TestLayout();
           test.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    Hi!
    Thanks for that Sir! heres my new code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TestLayout extends JFrame{
        //private JTextField text;   
        private IntegerTextField text;
        private JButton btnOne, btnTwo, btnThree, btnFour, btnFive,
                        btnSix, btnSeven, btnEight, btnNine, btnZero,
                        btnAdd, btnSubtract, btnMultiply, btnDivide,
                        btnSqrRt, btnModulo, btnBack, btnCE;
        private JPanel northPanel, centerPanel, southPanel;
        private int textNum;
        public TestLayout(){
           Container container = getContentPane();
           //text = new JTextField(14);
           //text = new TestLayout().new IntegerTextField(14);
           text = new IntegerTextField(14);
           text.setPreferredSize(new Dimension(255, 20));
           text.setHorizontalAlignment(JTextField.TRAILING);
           text.addActionListener(new ActionHandler());
           northPanel = new JPanel();
           northPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
           northPanel.add(text);
           container.add(northPanel, BorderLayout.NORTH);
           centerPanel = new JPanel();
           centerPanel.setLayout(new GridLayout(4, 4));
           btnOne = new JButton("1");
           btnTwo = new JButton("2");
           btnThree = new JButton("3");
           btnFour = new JButton("4");
           btnFive = new JButton("5");
           btnSix = new JButton("6");
           btnSeven = new JButton("7");
           btnEight = new JButton("8");
           btnNine = new JButton("9");
           btnZero = new JButton("0");
           btnMultiply = new JButton("*");
           btnDivide = new JButton("/");
           btnAdd = new JButton("+");
           btnSubtract = new JButton("-");
           btnSqrRt = new JButton("sqrt");
           btnModulo = new JButton("%");
           centerPanel.add(btnOne);
           centerPanel.add(btnTwo);
           centerPanel.add(btnThree);
           centerPanel.add(btnFour);      
           centerPanel.add(btnFive);
           centerPanel.add(btnSix);
           centerPanel.add(btnSeven);
           centerPanel.add(btnEight);      
           centerPanel.add(btnNine);
           centerPanel.add(btnZero);
           centerPanel.add(btnMultiply);
           centerPanel.add(btnDivide);      
           centerPanel.add(btnAdd);
           centerPanel.add(btnSubtract);
           centerPanel.add(btnSqrRt);
           centerPanel.add(btnModulo);      
           container.add(centerPanel, BorderLayout.CENTER);
           southPanel = new JPanel();
           southPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
           btnBack = new JButton("Backspace");
           btnCE   = new JButton("   CE    ");
           southPanel.add(btnBack);
           southPanel.add(btnCE);
           container.add(southPanel, BorderLayout.SOUTH);
           setSize(275, 250);
           setVisible(true);
        private class ActionHandler implements ActionListener {
           public void actionPerformed(ActionEvent event){
               if(event.getSource() == text)
                  computeText();
        private void computeText(){
           int num = Integer.parseInt(text.getText()) -1;
           text.setText(String.valueOf(num));
        private class IntegerTextField extends JTextField{
           //final static String badchars = "`~!@#$%^&*()_+=\\|\"':;?/>.<, ";
           final static String badchars = "`~!@#$%^&*()_+=\\|\"':;?/><, ";
           public IntegerTextField(int columns){
                  super(columns);
           public void processKeyEvent(KeyEvent event){
                  char c = event.getKeyChar();
                if ( (Character.isLetter(c) && !event.isAltDown())
                     || badchars.indexOf(c) > -1) {
                     event.consume();
                     return;
                if ( (c == '-') && getDocument().getLength() > 0 )
                     event.consume();
                else if( (c == '.') && getText().indexOf(c) > -1 )
                     event.consume();
                else
                     super.processKeyEvent(event);
        public static void main(String args[]){
           TestLayout test = new TestLayout();
           //test = new TestLayout();
           test.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

  • Problem in using KeyEvent.consume()

    Hi friends
    I am using KeyEvent.consume() for JTextField with KeyPressed and KeyTyped events, some times it cosumes and some time it don't. I would like to stop displaying some chars in text field by using consume(), ie basically validation part.
    Thanks
    Rammohan

    Are there specific keys that it won't consume?

  • KeyEvent.consume() problem for BACKSPACE

    Hi!
    I have the following problem - I want to disable the BACKSPACE key input for a JTextArea. I�ve done it like this:
    private class MyKeyAdapter extends KeyAdapter {
    public void keyPressed (KeyEvent e) {
    if (e.getKeyCode()==KeyEvent.VK_BACK_SPACE) e.consume();
    This method works for other keys but why not for BACKSPACE? Checking if the event has been consumed with KeyEvent.isConsumed() returns "true" like it should, but the event still gets processed in JTextArea.
    Thanx in advance,
    bbruno

    Here, try the following with a document filter that filters out VK_DELETE and VK_BACK_SPACE:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.event.*;
    public class TxtDemo extends JFrame {
       public static void main(String[] args) {
          JFrame F=new TxtDemo("Test Window");
          F.pack();
          F.setVisible(true);
          F.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
                System.exit(0);
       TxtDemo(String title) {
          super(title);
          JTextArea textArea = new JTextArea(5, 20);
          DocumentFilter filter = new DocumentFilter() {
             public void insertString(DocumentFilter.FilterBypass fb,int offset, String string, AttributeSet attr) throws BadLocationException {
                super.insertString(fb,offset,string,attr);
             public void remove(DocumentFilter.FilterBypass fb, int offset, int length) {  
                // do nothing
             public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
                super.replace(fb,offset,length,text,attrs);
          ((AbstractDocument) textArea.getDocument()).setDocumentFilter(filter);
          getContentPane().add(textArea);
    }Here is the same version that can be cut-n-paste:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.event.*;
    public class TxtDemo extends JFrame {
    public static void main(String[] args) {
    JFrame F=new TxtDemo("Test Window");
    F.pack();
    F.setVisible(true);
    F.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    TxtDemo(String title) {
    super(title);
    JTextArea textArea = new JTextArea(5, 20);
    DocumentFilter filter = new DocumentFilter() {
    public void insertString(DocumentFilter.FilterBypass fb,int offset, String string, AttributeSet attr) throws BadLocationException {
    super.insertString(fb,offset,string,attr);
    public void remove(DocumentFilter.FilterBypass fb, int offset, int length) {  
    // do nothing
    public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
    super.replace(fb,offset,length,text,attrs);
    ((AbstractDocument) textArea.getDocument()).setDocumentFilter(filter);
    getContentPane().add(textArea);
    ;o)
    V.V.

  • KeyEvent.consume() not consumed...

    Hi,
    If I attach a KeyEventListener to a TextField and that I consume the KeyEvents in the keyPressed() and keyReleased() methods, should the keys typed appear in the field or not?
    TextField f = new TextField();
    f.addKeyEventListener(this);
    public void keyPressed(KeyEvent e)
      e.consume();
    }I think they should not appear, as described in http://java.sun.com/j2se/1.3/docs/guide/awt/designspec/events.html:
    There are cases where programs need to prevent certain types of events from being processed normally by a component (i.e. a builder wants to use mouse events to enable a user to graphically move a button around and it wants to prevent the mouse press from 'pushing' the button).
    But testing it on Win2K with Sun JDK1.4.1 or IBM JDK1.3 shows the characters typed in the text field.
    On the other hand, testing the same code on a PDA width Personal Java does not show the keys types in the text field.
    Which one is correct?

    Hi,
    After been puzzled by this one for a few days, I found the answer. You have to consume all key events, even if KEY_TYPED is a high-level event and the javadoc for consume() says that it works only with low-level events!

  • KeyEvent.consume() doesn't work

    I have JFormattedTextField subclassed and implement a KeyListener to avoid typing invalid characters. so i implemented:
         * Implements KeyListener.
        public void keyPressed(KeyEvent event) {
            System.out.println("keyPressed: "+event);
            //verify:
            int keyCode = event.getKeyCode();
            switch (keyCode) {
            case KeyEvent.VK_T :
                System.out.println("valid: "+keyCode);
                break;
            default:
                System.out.println("invalid: "+keyCode);
                event.consume();
                break;
        }//keyPressed()The system out's are correct ("valid", "invalid"), but the invalid characters are still typed in the textfield - even though i call event.consume(). ?

    i had to introduce a class variable as a flag and also implement the other methods of KeyListener:
         * Implements KeyListener.
        public void keyPressed(KeyEvent event) {
            //verify:
            int keyCode = event.getKeyCode();
            switch (keyCode) {
            case KeyEvent.VK_T :
            case KeyEvent.VK_ESCAPE :
                isKeyConsumed = false;
                break;
            default:
                event.consume();
                isKeyConsumed = true;
                break;
        }//keyPressed()
         * Implements KeyListener.
        public void keyTyped(KeyEvent event) {
            if (isKeyConsumed) {
                event.consume();
        }//keyTyped()
         * Implements KeyListener.
        public void keyReleased(KeyEvent event) {
           if (isKeyConsumed) {
               event.consume();
        }//keyReleased()not pretty, but it works as expected.

  • KeyTyped(KeyEvent) consumes CTRL key actions

    hey there,
    using a single CTRL key the method "keyTyped()" will never be called, why? Is there anything, that consumes the event before the method is called? I'd like to do without the tow methods keyPressed() and keyReleased(). Visiting the component sources didn't help.
    thx in advance!
    -hostmonsta

    Hi,
    You can override the processKeyEvent(KeyEvent e)
    method of your control to get the CTRL keystroke.
    protected void processKeyEvent(KeyEvent e)
    super.processKeyEvent(e);
    if(e.getID() == KeyEvent.KEY_PRESSED)
    if(e.getKeyCode() == KeyEvent.VK_CONTROL)
    // do your logic

  • How to consume key events

    I would like to create a subclass of TextBox that only allows numeric input. My idea was to provide my own onKeyType() handler and consume any key events that do not correspond to digits. However, I can't find any way to consume key events from further processing. How do I do this?
    Are there any other suggestions how to accomplish the task of providing your own filter concerning valid key input?
    /Bengt

    I also wanted a kind of validators for the TextBox class of JavaFX. So I've tried solving the problem using the SwingTextField class and some Java APIs. The following is my code for a SwingTextField accepting only digits, but I do want it to be much simpler.
    import java.awt.AWTEvent;
    import java.awt.event.AWTEventListener;
    import java.awt.event.KeyEvent;
    import java.awt.Toolkit;
    import javafx.ext.swing.SwingTextField;
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    import javax.swing.JComponent;
    class DigitKeyEventHookListener extends AWTEventListener {
        public-init var  source:JComponent;
        public  override function  eventDispatched( event:AWTEvent):Void {
            if (event.getSource().equals(source)) {
                var keyEvent : KeyEvent = event as KeyEvent;
                var keyCharacter = keyEvent.getKeyChar();
                var isDigit = false;
                var code = keyEvent.getKeyCode();
               if ((KeyEvent.VK_0 <= keyCharacter) and (keyCharacter <= KeyEvent.VK_9)) {
                       isDigit = true;
                if ((code ==KeyEvent.VK_DELETE) or (code ==KeyEvent.VK_BACK_SPACE)) {
                    isDigit = true;
                if ((code ==KeyEvent.VK_LEFT) or (code ==KeyEvent.VK_RIGHT)) {
                    isDigit = true;
               if (not isDigit) {
                    keyEvent.consume();
    function createSwingTextField() : SwingTextField{
        var field = SwingTextField {
            columns:12
        var listener =  DigitKeyEventHookListener{
            source: field.getJTextField()
        Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK);
        return field;
    Stage {
        title: "Digit Box"
        width: 200
        height: 80
        scene: Scene {
            content: createSwingTextField()
    }

  • EventHandler T T doesn't recognize KeyEvent, bug?

    "type argument KeyEvent is not within bounds of Type-Variable T
    where T is a Type-Variable
    T extends Event declared in the interface EventHandler
    {code}
    http://docs.oracle.com/javafx/2/events/handlers.htm  this code doesn't work
    {code}
    Example 4-3 Handler for the Key Nodes
    private void installEventHandler(final Node keyNode) {
        // handler for enter key press / release events, other keys are
        // handled by the parent (keyboard) node handler
        final EventHandler<KeyEvent> keyEventHandler =
            new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        setPressed(keyEvent.getEventType()
                            == KeyEvent.KEY_PRESSED);
                        keyEvent.consume();
        keyNode.setOnKeyPressed(keyEventHandler);
        keyNode.setOnKeyReleased(keyEventHandler);
    {code}
    nor does this code, which I copied from a eventHandler<MouseEvent>
    {code}
    class keyHandler implements EventHandler<KeyEvent>
    private final Node node;
        keyHandler(Node node)
           this.node= node ;
        @Override
        public void handle(KeyEvent event)
    {code}
    I'm going to make a jira report once I get confirmation from someone here, even though it's pretty obvious since the Tutorial example produced the same error.
    I am using Netbeans Lambda 8, with JDK 8 build-84
    InputEvent doesn't work either, going to try some others...  so far MouseEvent and DragEvent are the only working ones.
    Edited by: KonradZuse on Apr 13, 2013 10:44 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Wow :p.... I completely forgot about the duplicate set of imports.... I always do control + alt + i to import everything, so sometimes AWT stuff pops in there when it shouldn't, suprirsed I didn't think of that myself, but 2 am coding does that to you :p.
    Thanks a ton, I really appreciate it, i had no idea what was going on hahaha...
    I think it's weird that MouseEvent and DragEvent are set to FX import first... Is there a settign in netbeans that I can force the importer to use FX > all? Most of the time it's good, but as you see in this case sometimes AWT likes to bother me :P
    Edited by: KonradZuse on Apr 14, 2013 11:02 AM

  • Anybody know of a SIMPLE highlighting editor?

    I've been trying to understand the Swing text classes by writing a syntax highlighting editor but I'm continually frustrated by the difficulty of understanding the examples I've found.
    The Prinzing example on the Sun site is sort of understandable but I don't understand it well enough to extend it.
    SimplyHTML is wonderfully documented but WAY beyond my ability.
    The Ostermiller example is easy to understand does not use the 'plug-in' design that the text classes seem to be designed for. In addition Ostermiller uses setCharacterAttributes() which does not work for me.
    Any suggestions for other examples?
    Thanks,
    --beeky                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Pasted below is the code of the editor u require. Should u need further information, feel free to get in touch with me.
    I hope this code will help u
    Sachin
    import com.pg.sourceone.gdet.util.ValidateUIData;
    import javax.swing.JTextField;
    import javax.swing.JTable;
    import javax.swing.event.CellEditorListener;
    import javax.swing.event.ChangeEvent;
    import javax.swing.table.TableColumn;
    import javax.swing.DefaultCellEditor;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.FocusEvent;
    import java.awt.Toolkit;
    import java.awt.Color;
    import java.text.NumberFormat;
    import java.text.ParseException;
    import java.util.Hashtable;
    import java.util.Vector;
    import java.util.Locale;
    public class CellHighlightEditor implements KeyListener, CellEditorListener
    /** integer holding the length of the column name */
    int intLength = 0;
    /** integer holding the column index */
    int intEditCol = -1;
    /** integer holding the row index */
    int intEditRow = -1;
    /** boolean holding the status after the validation function */
    boolean blnValid = true;
    /** TableColumn Object */
    TableColumn tcEditCol;
    /** DefaultCellEditor Object */
    DefaultCellEditor dceCols;
    /** HighlightTableCellRenderer Object */
    HighlightTableCellRenderer highlightTableCellObj;
    /** String holding the column name */
    String strEditCol = "";
    /** String holding the previous value of the cell */
    String strOldCellValue = null;
    /** String holding the current cell value */
    String strNewCellValue = null;
    /** String holding the cell number */
    String strCellNo = "";
    /** String holding the data retrived from the Hashtable hshType */
    String strDataType = "";
    /** Hashtable Object */
    Hashtable hshOldValues;
    /** Hashtable Object */
    Hashtable hshType;
    /** Hashtable Object */
    Hashtable hshLength;
    /** TableComponent Object */
    BldrTableComponent tblTemp = null;
    /** JTextField Object */
    public JTextField txfEditor;
    /** NumberFormat Object */
    NumberFormat nfData;
    /** Vector Object */
    Vector vctRows;
    /** Vector Object */
    Vector vctCols;
    /** ValidateUIData Object */
    ValidateUIData vld;
    * Constructor CellHighlightEditor.
    * @param TableComponent tblEditor
    * @param Vector vctRowEditor
    * @param Vector vctColsEditor
    public CellHighlightEditor(BldrTableComponent tblEditor, Vector vctRowEditor,
    Vector vctColsEditor)
    tblTemp = tblEditor;
    /* instantiate the ValidateUIData object */
    vld = new ValidateUIData();
    /* instantiate the hshType object */
    hshType = new Hashtable();
    /* instantiate the hshOldValues object */
    hshOldValues = new Hashtable();
    /* instantiate the hshLength object */
    hshLength = new Hashtable();
    /* instantiate the txfEditor object */
    txfEditor = new JTextField();
    /* instantiate the vctRows object */
    vctRows = new Vector();
    /* instantiate the vctCols object */
    vctCols = new Vector();
    /* instantiate the highlightTableCellObj object */
    highlightTableCellObj = new HighlightTableCellRenderer();
    txfEditor.addKeyListener(this);
    tblTemp.table.addKeyListener(this);
    nfData = NumberFormat.getInstance(Locale.US);
    for (int i = 0; i < vctRowEditor.size(); i++)
    vctRows.addElement(((Vector) vctRowEditor.elementAt(i)).clone());
    } // end of for
    for (int i = 0; i < vctColsEditor.size(); i++)
    vctCols.addElement(vctColsEditor.elementAt(i));
    } // end of for
    } // end of constructor
    * Method sets the data type and its length of the data present
    * in the JTable.
    * @param String strCol
    * @param int intLength
    * @param String strType
    public void setTypeNLength(String strCol, int intLength, String strType)
    hshLength.put(strCol, String.valueOf(intLength));
    hshType.put(strCol, strType);
    highlightTableCellObj.setTypeNLngth(hshType);
    } // end of setTypeNLength method
    * Method sets the JTable Column editable.
    * @param String strCol
    public void setColEditor(String strCol)
    dceCols = new DefaultCellEditor(txfEditor);
    dceCols.setClickCountToStart(1);
    dceCols.addCellEditorListener(this);
    tcEditCol =
    tblTemp.table.getColumnModel().getColumn(tblTemp.getColumnIndex(strCol));
    tcEditCol.setCellEditor(dceCols);
    tcEditCol.setCellRenderer(highlightTableCellObj);
    intEditCol = tblTemp.getColumnIndex(strCol);
    strEditCol = strCol;
    } // End of setColEditor method
    * Method used for removing highlighting.
    public void removeHighlighting()
    tblTemp.dataModel.resetHighlighting();
    } // End of removeHighlighting method
    * Method Invoked when a key has been Typed.
    * @param KeyEvent keyEvent
    public void keyTyped(KeyEvent keyEvent)
    intEditRow = tblTemp.table.getEditingRow();
    intEditCol = tblTemp.table.getEditingColumn();
    if ((intEditRow != -1) && (intEditCol != -1))
    strEditCol = tblTemp.table.getColumnName(intEditCol);
    strDataType =
    hshType.get(tblTemp.table.getColumnName(intEditCol)).toString();
    if (strDataType.equalsIgnoreCase("INTEGER"))
    blnValid = vld.staticIntegerValidation(keyEvent);
    else if (strDataType.equalsIgnoreCase("DECIMAL"))
    blnValid =
    vld.decimalValidation(dceCols.getCellEditorValue().toString(),keyEvent);
    else if (strDataType.equalsIgnoreCase("FILTERED_STRING"))
    blnValid = vld.charValidation("-_ ",keyEvent);
    if (blnValid == true)
    strNewCellValue = dceCols.getCellEditorValue().toString();
    if ((strNewCellValue != null) &&!strNewCellValue.equals(""))
    intLength =
    Integer
    .parseInt(hshLength.get(tblTemp.table.getColumnName(intEditCol))
    .toString());
    if ((strNewCellValue.indexOf('.') >= 0) && (keyEvent.getKeyChar() == '.'))
    keyEvent.consume();
    vld.staticLengthValidation(strNewCellValue, intLength, keyEvent);
    } // end of if ((strNewCellValue != null) &&!strNewCellValue.equals(""))
    } //end of boolean
    } // end of if ((intEditRow != -1) && (intEditCol != -1))
    } // end of keyTyped method
    * Method Invoked when a key has been pressed.
    * @param KeyEvent keyEvent
    public void keyPressed(KeyEvent keyEvent)
    } // end of keyPressed method
    * Method Invoked when a key has been pressed.
    * @param KeyEvent keyEvent
    public void keyReleased(KeyEvent keyEvent)
    strNewCellValue = dceCols.getCellEditorValue().toString();
    } // end of keyReleased method
    * Method editingCanceled.
    * @param ChangeEvent chngEvent
    public void editingCanceled(ChangeEvent chngEvent)
    } // end of editingCanceled metod
    * Method to notify that the user has finished editing the JTable
    * data.
    * @param ChangeEvent chngEvent
    public void editingStopped(ChangeEvent chngEvent)
    if ((intEditRow != -1) && (intEditCol != -1))
    strOldCellValue =
    ((Vector) vctRows.elementAt(intEditRow))
    .elementAt(vctCols.indexOf(strEditCol)).toString();
    if (!(strNewCellValue.equals(strOldCellValue)))
    // tblTemp.dataModel.setCellBackground(highlightTableCellObj, intEditRow,
    // strEditCol);
    else
    // tblTemp.dataModel.resetCellBackground(highlightTableCellObj,
    // intEditRow, strEditCol);
    } // end of else
    } // end of if ((intEditRow != -1) && (intEditCol != -1))
    tblTemp.table.editingStopped(chngEvent);
    } // end of editingStopped method
    }// end of CellHighlightEditor class

  • JTextPane and Unicodes

    Hi,
    I am using unicodes in JTextPane yes it is working well but it does not suport some of them. I mean it doesnt show some of codes but it displays box at that place. So what should i do.
    When I press a key with the especial unicode character it also shows English character. I just want unicode charater over there. So i have these two problems. Plz answer me if its possible.

    1. Sounds like you're using a font which doesn't have all the Urdu characters.
    2. keyEvent.consume();

  • Using java.beans.EventHandler to create javafx.event.EventHandler instances

    One thing I do not like about the JavaFX EventHandler is all the anonymous classes that need to be created. This messes up the way the code looks and I heard that creating all these anonymous classes adds to the total number of classes that get loaded.
    In searching for a way around this I found java.beans.EventHandler's create method. This method (there are a few variations of it) its suppose to provide a one liner to create anonymous implementations of listener interfaces (like JavaFX's EventHandler). So I decided to try it out against some of the sample JavaFX code that is out there.
    I used.... http://docs.oracle.com/javafx/2.0/events/KeyboardExample.java.htm... as my test code.
    I replaced...
            private void installEventHandler(final Node keyNode) {
                // handler for enter key press / release events, other keys are
                // handled by the parent (keyboard) node handler
                final EventHandler keyEventHandler = new EventHandler<KeyEvent>() {
                    @Override
                    public void handle(final KeyEvent keyEvent) {
                        if (keyEvent.getCode() == KeyCode.ENTER) {
                            setPressed(keyEvent.getEventType() == KeyEvent.KEY_PRESSED);
                            keyEvent.consume();
                keyNode.setOnKeyPressed(keyEventHandler);
                keyNode.setOnKeyReleased(keyEventHandler);
            }with....
            private void installEventHandler(final Node keyNode) {
                // handler for enter key press / release events, other keys are
                // handled by the parent (keyboard) node handler
                final EventHandler keyEventHandler = (EventHandler)java.beans.EventHandler.create(EventHandler.class, this, "handle", "");
                keyNode.setOnKeyPressed(keyEventHandler);
                keyNode.setOnKeyReleased(keyEventHandler);
    public void handle(final KeyEvent keyEvent) {
                if (keyEvent.getCode() == KeyCode.ENTER) {
                    setPressed(keyEvent.getEventType() == KeyEvent.KEY_PRESSED);
                    keyEvent.consume();
            }It worked. The new code behaved just like the old code.
    One caveat though. The class count did in fact go up by about 20 classes. I ran multiple runs and this was true for all of them. But I only applied this technique on one anonymous class. It could be the case that the real savings in class count come after many instances of swapping out anonymous classes with this technique.
    From the javadoc
    "Also, using EventHandler in large applications in which the same interface is implemented many times can reduce the disk and memory footprint of the application.
    The reason that listeners created with EventHandler have such a small footprint is that the Proxy class, on which the EventHandler relies, shares implementations of identical interfaces. For example, if you use the EventHandler create methods to make all the ActionListeners in an application, all the action listeners will be instances of a single class (one created by the Proxy class). In general, listeners based on the Proxy class require one listener class to be created per listener type (interface), whereas the inner class approach requires one class to be created per listener (object that implements the interface)."
    Edited by: jmart on Apr 23, 2012 2:13 AM

    Well, the idea is that with Java 8 they can be rewritten to something like this:
    private void installEventHandler(final Node keyNode) {
                // handler for enter key press / release events, other keys are
                // handled by the parent (keyboard) node handler
                EventHandler keyEventHandler = keyEvent => {
                        if (keyEvent.getCode() == KeyCode.ENTER) {
                            setPressed(keyEvent.getEventType() == KeyEvent.KEY_PRESSED);
                            keyEvent.consume();
                keyNode.setOnKeyPressed(keyEventHandler);
                keyNode.setOnKeyReleased(keyEventHandler);
            }Basically what you are doing now is sacrificing performance (both in real performance and in a lot of extra garbage created) for a little bit of memory gain. Unless you have good reasons and measurements to back this up I think this would definitely qualify as premature optimization.
    I'm a heavy user of anonymous inner classes myself, having several hundreds of them now in my project and I have yet to run into problems. I often write code like the example below purely for readability and convience:
    Set<String> someSet = new HashSet<>() {{
      add("A");
      add("B");
    new HBox() {{
      getChildren.add(new VBox() {{
        getChildren.add(new Label("Hi"));
      getChildren.add(new VBox() {{
        getChildren.add(new Label("There"));
    }};

  • How do you override the WINDOWS key?

    I'm writing or rather rewriting a game. I would like to override the windows key to do some function in the game without invoking the windows menu. Is this possible, and if so how?
    Below is a sample bit of code I used to see what key codes, locations, and events were fired while pressing various keys. I made the key pressed/typed/released methods consume the events in an attempt to block the windows menu from coming up. I tried using a KeyEventDispatcher to catch all key events and consume them there, but it still displays the windows menu (on Windows 2000 at least).
    I have searched the forums and the all mighty Google to no avail. Please help me if you can. Thank you.
    import java.awt.Dimension;
    import java.awt.KeyEventDispatcher;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.FocusManager;
    import javax.swing.JFrame;
    public class Test extends JFrame implements KeyListener, KeyEventDispatcher
      public Test()
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addWindowListener(new WindowAdapter()
          @Override
          public void windowClosing(WindowEvent windowEvent)
            System.exit(0); //close all windows and exit
        FocusManager.getCurrentManager().addKeyEventDispatcher(this);
        this.addKeyListener(this);
        this.pack();
      public static void main(String[] arguments)
        Test frame;
        frame = new Test();
        frame.setTitle("Test Frame");
        frame.setPreferredSize(new Dimension(200,200));
        frame.invalidate();
        frame.pack();
        frame.setVisible(true);
      // this doesn't stop windows key from being processed whether true or false
      // if it is true the keyPressed, keyTyped, and keyReleased don't get called
      public boolean dispatchKeyEvent(KeyEvent keyEvent)
        System.out.println("dispatchKeyEvent " + keyEvent);
        return true;
      public void keyPressed(KeyEvent keyEvent)
        System.out.println("keyPressed " + keyEvent);
        keyEvent.consume();
      public void keyReleased(KeyEvent keyEvent)
        System.out.println("keyReleased " + keyEvent);
        keyEvent.consume();
      public void keyTyped(KeyEvent keyEvent)
        System.out.println("keyTyped " + keyEvent);
        keyEvent.consume();
    }

    Thanks for the reply. That is basically all I wanted to confirm. I wanted to allow the player to redefine the windows key to some game specific command. I can do this for all of the other keys I was able to test except for that one.
    If someone uses it on something other than windows they can redefine any key that maps to one of theirs. Since I don't have any alternate systems or keyboards to test on I won't bother making other keyboard configurations for the time being, if ever.

  • Issue with a class extending EventHandler MouseEvent

    Hello all,
    I originally had a nested class that was a used for mouseEvents. I wanted to make this it's own class, so I can call it directly into other class objects I have made, but for some reason it isn't working and I'm getting an eror
    here is the code:
    public class MouseHandler implements EventHandler<MouseEvent>
        private double sceneAnchorX;
        private double sceneAnchorY;
        private double anchorAngle;
        private Parent parent;
        private final Node nodeToMove ;
       MouseHandler(Node nodeToMove)
           this.nodeToMove = nodeToMove ;
        @Override
        public void handle(MouseEvent event)
          if (event.getEventType() == MouseEvent.MOUSE_PRESSED)
            sceneAnchorX = event.getSceneX();
            sceneAnchorY = event.getSceneY();
            anchorAngle = nodeToMove.getRotate();
            event.consume();
          else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED)
              if(event.isControlDown())
                  nodeToMove.setRotationAxis(new Point3D(sceneAnchorY,event.getSceneX(),0));
                  nodeToMove.setRotate(anchorAngle + sceneAnchorX -  event.getSceneX());
                  sceneAnchorX = event.getSceneX();
                  sceneAnchorY = event.getSceneY();
                  anchorAngle = nodeToMove.getRotate();
                  event.consume();
              else
                double x = event.getSceneX();
                double y = event.getSceneY();
                nodeToMove.setTranslateX(nodeToMove.getTranslateX() + x - sceneAnchorX);
                nodeToMove.setTranslateY(nodeToMove.getTranslateY() + y - sceneAnchorY);
                sceneAnchorX = x;
                sceneAnchorY = y;
                event.consume();
          else if(event.getEventType() == MouseEvent.MOUSE_CLICKED)
            //  nodeToMove.setFocusTraversable(true);
               nodeToMove.requestFocus();
               event.consume();
                         nodeToMove.setOnKeyPressed((KeyEvent)
    ->{
         if(KeyCode.UP.equals(KeyEvent.getCode()))
             nodeToMove.setScaleX(nodeToMove.getScaleX()+ .1);
             nodeToMove.setScaleY(nodeToMove.getScaleY()+ .1);
             nodeToMove.setScaleZ(nodeToMove.getScaleZ()+ .1);
             System.out.println("kaw");
             KeyEvent.consume();
         if(KeyCode.DOWN.equals(KeyEvent.getCode()))
             if(nodeToMove.getScaleX() > 0.15)
             nodeToMove.setScaleX(nodeToMove.getScaleX()- .1);
             nodeToMove.setScaleY(nodeToMove.getScaleY()- .1);
             nodeToMove.setScaleZ(nodeToMove.getScaleZ()- .1);
             System.out.println(nodeToMove.getScaleX());
             KeyEvent.consume();
         nodeToMove.setOnScroll((ScrollEvent)
                 ->{
             if(nodeToMove.isFocused())
                        if(ScrollEvent.getDeltaY() > 0)
                            nodeToMove.setTranslateZ(10+nodeToMove.getTranslateZ());
                        else
                            nodeToMove.setTranslateZ(-10+nodeToMove.getTranslateZ());
           ScrollEvent.consume();
    }This is the class where I call it.
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.Box;
    * @author Konrad
    public class Display extends Pane
        Box b;
        PhongMaterial pm = new PhongMaterial(Color.GRAY);
        public Display(Double x, Double y,Double width, Double height)
             super();
             b = new Box(width, height,10);
             setPrefSize(width,height);
             relocate(x, y);
             b.setMaterial(pm); 
             b.addEventFilter(MouseEvent.ANY, new MouseHandler(this));
             getChildren().add(b);
    }There is no red dot stating the class doesn't exist, or anything is wrong, but when I run it I get an error.
    here is the error:
    C:\Users\Konrad\Documents\NetBeansProjects\3D\src\3d\Display.java:29: error: cannot find symbol
             b.addEventFilter(MouseEvent.ANY, new MouseHandler(this));
      symbol:   class MouseHandler
      location: class DisplayThis is another class from the one that it was originally "nested" in(sorry if I'm not using correct terms). The other class, as well as this, produce the same error(this one was just smaller and eaiser to use as an example).
    The code is exactly the same.
    Originally I thought that the MouseEvent class wasn't an FX class, so I switched it and thought it worked, tried it on the Display class it didn't, tried it on the first one and yeah still didn't, so not too sure what happened there :(.
    Thanks,
    ~KZ
    Edited by: KonradZuse on Jun 7, 2013 12:15 PM
    Edited by: KonradZuse on Jun 7, 2013 12:38 PM
    Edited by: KonradZuse on Jun 7, 2013 12:39 PM

    Last time that was the issue I was having for a certain case; however this seems to be different, here is the list of imports for each class.
    MouseHandler:
    import javafx.event.EventHandler;
    import javafx.geometry.Point3D;
    import javafx.scene.Node;
    import javafx.scene.Parent;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.MouseEvent;Display:
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.Box;draw:
    import java.io.File;
    import java.sql.*;
    import javafx.application.Application;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.ActionEvent;
    import javafx.geometry.Rectangle2D;
    import javafx.scene.Group;
    import javafx.scene.PerspectiveCamera;
    import javafx.scene.PointLight;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.ListCell;
    import javafx.scene.control.ListView;
    import javafx.scene.control.Menu;
    import javafx.scene.control.MenuBar;
    import javafx.scene.control.MenuItem;
    import javafx.scene.control.TextField;
    import javafx.scene.input.ClipboardContent;
    import javafx.scene.input.DataFormat;
    import javafx.scene.input.DragEvent;
    import javafx.scene.input.Dragboard;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.input.TransferMode;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.TriangleMesh;
    import javafx.stage.FileChooser;
    import javafx.stage.FileChooser.ExtensionFilter;
    import javafx.stage.Screen;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    import jfxtras.labs.scene.control.window.Window;
    import org.controlsfx.dialogs.Action;
    import org.controlsfx.dialogs.Dialog;Edited by: KonradZuse on Jun 7, 2013 2:27 PM
    Oddly enough I tried it again and it worked once, but the second time it error-ed out again, so I'm not sure what the deal is.
    then I ended up getting it to work again in the draw class only but when I tried to use the event I get this error.
    J a v a M e s s a g e : 3 d / M o u s e H a n d l e r
    java.lang.NoClassDefFoundError: 3d/MouseHandler
         at shelflogic3d.draw.lambda$5(draw.java:331)
         at shelflogic3d.draw$$Lambda$16.handle(Unknown Source)
         at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
         at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
         at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
         at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
         at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
         at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
         at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
         at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
         at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
         at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
         at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
         at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
         at javafx.event.Event.fireEvent(Event.java:202)
         at javafx.scene.Scene$DnDGesture.fireEvent(Scene.java:2824)
         at javafx.scene.Scene$DnDGesture.processTargetDrop(Scene.java:3028)
         at javafx.scene.Scene$DnDGesture.access$6500(Scene.java:2800)
         at javafx.scene.Scene$DropTargetListener.drop(Scene.java:2771)
         at com.sun.javafx.tk.quantum.GlassSceneDnDEventHandler$3.run(GlassSceneDnDEventHandler.java:85)
         at com.sun.javafx.tk.quantum.GlassSceneDnDEventHandler$3.run(GlassSceneDnDEventHandler.java:81)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.javafx.tk.quantum.GlassSceneDnDEventHandler.handleDragDrop(GlassSceneDnDEventHandler.java:81)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleDragDrop(GlassViewEventHandler.java:595)
         at com.sun.glass.ui.View.handleDragDrop(View.java:664)
         at com.sun.glass.ui.View.notifyDragDrop(View.java:977)
         at com.sun.glass.ui.win.WinDnDClipboard.push(Native Method)
         at com.sun.glass.ui.win.WinSystemClipboard.pushToSystem(WinSystemClipboard.java:234)
         at com.sun.glass.ui.SystemClipboard.flush(SystemClipboard.java:51)
         at com.sun.glass.ui.ClipboardAssistance.flush(ClipboardAssistance.java:59)
         at com.sun.javafx.tk.quantum.QuantumClipboard.flush(QuantumClipboard.java:260)
         at com.sun.javafx.tk.quantum.QuantumToolkit.startDrag(QuantumToolkit.java:1277)
         at javafx.scene.Scene$DnDGesture.dragDetectedProcessed(Scene.java:2844)
         at javafx.scene.Scene$DnDGesture.process(Scene.java:2905)
         at javafx.scene.Scene$DnDGesture.access$8500(Scene.java:2800)
         at javafx.scene.Scene$MouseHandler.process(Scene.java:3564)
         at javafx.scene.Scene$MouseHandler.process(Scene.java:3379)
         at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3331)
         at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1612)
         at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2399)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:312)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:237)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:354)
         at com.sun.glass.ui.View.handleMouseEvent(View.java:514)
         at com.sun.glass.ui.View.notifyMouse(View.java:877)
         at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
         at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
         at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
         at java.lang.Thread.run(Thread.java:724)
    Caused by: java.lang.ClassNotFoundException: shelflogic3d.MouseHandler
         at java.net.URLClassLoader$1.run(URLClassLoader.java:365)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:353)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
         ... 50 more
    Exception in thread "JavaFX Application Thread" E..........After the E comes a bunch of random stuff with drag and drop and such (since I'm dragging an item, and then creating it and giving it the event in question).
    Line 331 is                      b.addEventHandler(MouseEvent.ANY, new MouseHandler(b));

  • Restricting data in the table cell

    Hi,
    I want to know how to restrict the data entereed in the table cell not more than 10 characters. How can i handle this.

    You need to supply your own cell editor instead of using the default one. Create a subclass of JTextField that consumes the keyPressed event when the text length is 10 characters, and call:
    theTableColumn.setCellEditor(new DefaultCellEditor(theTextField));

Maybe you are looking for