Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Document/Element question (for extreme Swing gurus)



Kenneth McDonald wrote:
|Anyway, I'm trying to build an Element type for use with text panes,
|that permit "fields", i.e.
|one could place two fields side by side, but they would still have a
|concept of a difference
|between them; text would be entered into either one field or the other,
|depending on the
|location of the cursor.
|
| ...
|
|However, if I want each element to represent a field, and want to ensure
|that the cursor
|is unambiguously in only one field, I need to have a separation between
|elements:
|[a,b],[b+1,c],[c+1,d]...
|because otherwise I could not (for example) determine if a cursor at
|position c was in the
|second or third field element.

It's not clear to me whether your "fields" are distinct UI components or simply subdivisions of a single JTextField. If the former, then the separation you seem to want is automatic, since each JTextField counts its characters separately. I assume, then, that you're trying to divide a single JTextField into subfields.

I don't think you can do what you want. The problem is that the cursor (that is, the insertion point) simply isn't *in* anything. It's *between* things--between characters, specifically. Suppose your field is divided up as "AAAABBBCCCCCCCDDDD" (where each letter indicates a field). Your user clicks between the B and C fields, placing the cursor (insertion point) between them. Has he clicked "in" the B field, or the C field? What does he do if it's not in the field he intended? Worse, suppose the cursor is clearly *in* the "B" subfield (between the second and third characters), and the user uses the cursor keys to move it left two characters, so that it's (apparently) between the A and B fields. Is it still in the B field, or has it moved into the A field? If in the B field, how would he move it into the A field? Press the "cursor left" key again? But then it would appear that nothing happened. (In general, how do you indicate which field the cursor is in?)
Even if you found a way to tell Swing that each chu
of text was a field, you're left with the problem that the cursor would still be *between* fields, still with no way to prefer one field over the other.

What having separate UI components does is to provide exactly the separation between items you seem to want, since each UI component has its own beginning and end. A single text field, on the other hand, has only one beginning and end, unless you introduce into the text field artificial beginning and end points for each field (the "dummy elements" you want to avoid).
What having separate UI components *also* does is to keep the separate fields from interacting. Subdividing a single text field means that typing something into field B affects field C (by moving the text within the field); your component therefore has to include code that cancels out that effect.

I don't see any advantage to not using separate UI components. If you want the user to not have to tab from one to the next, you can write listeners that do the focus-changing automatically when the text field is filled.

Glen Fisher
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >Document/Element question (for extreme Swing gurus) (From: Kenneth McDonald <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.