开发者

Overriding a deprecated JComponent method

In a rich client CRUD framework I'm working on, I have a so-called edit panel, which as the name suggests, is involved in editing row objects via the usual swing input components.

Now, the panel has a default focus component field, which references the input field which should receive focus when the edit panel is initialized or cleared. The problem is the most logical name for the method which performs the focus request.

public boolean requestDefaultFocus()
  return getDefaultFocusComponent().requestFocusInWindow();
}

The edit panel extends JPanel so this overrides the now deprecated JComponent method. The method name I'm currently using to avoid this is setDefaultFocus().That just doesn't sound quite right, although I will be a开发者_开发问答ble to live with it in case the answer to the question turns out to be a resounding no.

So, what are your thoughts on overriding a deprecated method like that?


I would not recommend it. There's no way to stop your code from issuing deprecation warnings. It makes it look like there's something wrong. And that takes developer time to verify that the warnings are spurious.

How about setInitialFocus()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜