Tuesday, June 01, 2004

Swing interfaces, how do you implement yours?

I spent late Friday afternoon moaning about how, while extending JTextField, I couldn't consume character key presses before they were entered into the text field. Well of course you can, I was just being particularly stupid....it was Friday after all.

I had implemented the KeyListener interface, but only fulfilled my usual keyPressed method, which obviously gets called after the text field has dealt with text keys. After I'd realised what I'd done it got me to thinking. I have gotten into habits when implementing interfaces that I use a lot. For example, when constructing a new Swing component I also implement the LayoutManager interface, fulfill the layoutContainer method, call onto getPreferredSize from both min and max layout size methods and do nothing in the add and remove layout components. I then override the getPrefferedSize method to ensure I don't get into any infinate loops.

This works for me, but my concern is that I don't realise that this is what I'm doing any more, thus leading to the potential for such gotchas as the KeyListener problem. Well it's one to remember at any rate, and I made myself look soooo stupid over this one that I'm not going to forget it in a hurry. At least I can be thankful that ActionListener only has one method!


Anonymous said...

You should seriously consider taking a loom at JGoodies FormLayout. It takes about 10 mins to get your head around, but is incredibly flexible and provides some great layouts: http://www.jgoodies.com/freeware/forms/index.html

Sam Newman

Matt Large said...

We did look at JGoodies Forms, and for a long time this was going to be the route we were going to go down. Then as the requirements for the application were fleshed out and the visual designs done it became apparent that it just wouldn't work. Not really due to the look or layout, but because of the level of user interaction and feedback, which meant that almost all of the form components had to be custom built and the layout was very dynamic.

I understand that JGoodies could probably have produced the majority of what we wanted, but it's that last 5% that moved us in another direction. We needed extremely fine grained control over things to be able to produce exactly what was required.

However, I am still very impressed with JGoodies and plan to use it in the near future.

Wenhao Guo said...

arizona cardinals
coach outlet store
chicago bears
michael kors outlet online
soccer jerseys,soccer jerseys wholesale,soccer jerseys cheap,soccer jerseys for sale,cheap soccer jersey,usa soccer jersey,football jerseys
ugg boots on sale
cheap oakley sunglasses
true religion sale
kobe 9 elite
nike air max 2014
mont blanc
ed hardy outlet
philadelphia eagles
belstaff jackets
michael kors handbags sale
vans sneakers
michael kors handbags,michael kors outlet,michael kors outlet online,michael kors,kors outlet,michael kors outlet online sale,michael kors handbags clearance,michael kors purses,michaelkors.com,michael kors bags,michael kors shoes,michaelkors,cheap michael kors
nike free
north face outlet
nike air huarache,nike huarache,nike huarache sneakers,nike huarache shoes
pittsburgh steelers
boston celtics
ralph lauren
air jordan 11 free shipping
nike air max 90
swarovski outlet
michael kors online outlet
nike running shoes
baltimore ravens
winter jackets outlet
san antonio spurs
cheap uggs

Meiqing Xu said...

jimmy choo outlet store
oakley vault
ugg boots
reebok shoes
ray ban outlet
longchamp outlet
ghd flat iron
coach outlet online
true religion jeans
cheap omega watches
moncler outlet
nfl jerseys wholesale
moncler outlet
ralph lauren outlet
cheap basketball shoes
coach outlet
christian louboutin
michael kors outlet online
michael kors outlet clearance
adidas stan smith
lacoste polo shirts
puma shoes
moncler jackets
canada goose jackets
coach factory outlet
adidas gazelle
designer handbags outlet
vans shoes
pandora outlet
asics outlet
louboutin outlet
jordan shoes

Jian Zhuo said...

michael kors outlet online
true religion outlet
ugg australia
cheap nike air max
adidas shoes
ugg boots
polo ralph lauren outlet online
hollister clothing
cheap jordans
nike store

caiyan said...

coach outlet online
ray ban sunglasses discount
ralph lauren outlet
nike air huarache
cheap jerseys
coach outlet online
celine handbags
michael kors bags
pandora charms sale clearance