The Artima Developer Community
Sponsored Link

Java Buzz Forum
Focus in J2SE -> oh boy

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Marc Logemann

Posts: 594
Nickname: loge
Registered: Sep, 2002

Marc Logemann is founder of www.logentis.de a Java consultancy
Focus in J2SE -> oh boy Posted: Oct 6, 2003 5:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Marc Logemann.
Original Post: Focus in J2SE -> oh boy
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
Latest Java Buzz Posts
Latest Java Buzz Posts by Marc Logemann
Latest Posts From Marc's Java Blog

Advertisement
There are a lot of nice, modular and intuitive parts within J2SE. Most of them seem to be well designed and easy to understand. But not with the Focus API in J2SE. First of all, everyday problems seem to generate complicated code. Did you ever wanted to set a default focus of a component inside a Window? Then face it, you have to write windowListeners and stuff like this:

// Create frame and three buttons JFrame frame = new JFrame(); JButton component1 = new JButton("1"); JButton component2 = new JButton("2"); JButton component3 = new JButton("3"); // Set component with initial focus // Must be done before the frame is made visible InitialFocusSetter.setInitialFocus(frame, component2); class InitialFocusSetter { public static void setInitialFocus(Window w, Component c) { w.addWindowListener(new FocusSetter(c)); } public static class FocusSetter extends WindowAdapter { Component initComp; FocusSetter(Component c) { initComp = c; } public void windowOpened(WindowEvent e) { initComp.requestFocus(); // Since this listener is no longer needed, remove it e.getWindow().removeWindowListener(this); } } }

Perhaps i am still dreaming for a better world, but this is just too complicated for such a common task. I found some other crazy behaviors when working with requestFocus() under some circumstances which i cant easily demonstrate because of the space i would need for this. But for me, Focus API in Java is still braindamaged, and this even after a rework from Sun.
 

Read: Focus in J2SE -> oh boy

Topic: swt-designer finally out Previous Topic   Next Topic Topic: Tips for Java Guerilla Warfare #2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use