Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #959

Re: JFormattedTextField c

From "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this>
Subject Re: JFormattedTextField c
Message-ID <er4asc$bdk$1@wblv-ip-nnrp-1.saix.net> (permalink)
Newsgroups comp.lang.java.gui
References <qhire4xqgu.fsf@ruckus.brouhaha.com>
Date 2011-04-27 15:30 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
Eric Smith wrote:
> I asked:
>> Is there some way for an object to get notified when
>> a JFormattedTextField commits?
> And later I wrote:
>> The JFormattedTextField apparently
>> changes a "value" attribute when the field commits.
> [...]
>> when using a MaskFormatter, the field
>> doesn't seem to commit when return is pressed (and the contents are valid),
>> though it does commit if it loses the focus because I click in a
>> different field.
> 
> Rogan Dawes <discard@dawes.za.net> writes:
>> Use an ActionListener. But also see my response to your other mail.
> 
> Interesting.  The ActionListener fires if a return is pressed, but
> not if a commit occurs because the focus is lost.  So if I use this
> approach, I have to have both an ActionListener and a
> PropertyChangeListener.

You might also use a FocusListener to trigger the action. See 
JTextField.postActionEvent()

The FocusListener would trigger the event whenever focus is lost.

> It seems bizarre that there's no easy way to get notification of
> commits of a JFormattedTextField.  I think I'll take your other
> advice and go back to using a JTable.

The question is, what do you define as a commit? A commit suggests that 
there is some definite action that trigger the commit. That is typically 
something like "pressing enter", etc. And that is exactly what is 
happening here.

Otherwise you are talking about a keypress, and that is easy to monitor 
with a DocumentListener as well.

> I think some of my complaints about using the JTable are solved if
> instead of making my Memory class implement the AbstractTableModel, I
> use a separate object for that, as you did in your HexForm class.
> 
> Thanks,
> Eric

You did say that you didn't want your domain object to know about your 
GUI implementation, so making Memory implement AbstractTableModel is the 
wrong solution.

If you have your Memory class firing MemoryEvent's, create a 
MemoryTableModel that extends AbstractTableModel, and implements 
MemoryEventListener. This adapter class will simply translate 
MemoryEvent to TableModelEvent in one direction, and accesses to table 
cells into memory positions in the other direction.

This is quite a common pattern, in fact. See 
http://en.wikipedia.org/wiki/Adapter_pattern

Rogan

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

JFormattedTextField commi "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
  Re: JFormattedTextField c "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
    Re: JFormattedTextField c "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
      Re: JFormattedTextField c "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
      Re: JFormattedTextField c "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
        Re: JFormattedTextField c "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
          Re: JFormattedTextField c "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
            Re: JFormattedTextField c "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
              Re: JFormattedTextField c "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
  Re: JFormattedTextField c "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
    Re: JFormattedTextField c "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000

csiph-web