重写已弃用的 JComponent 方法

发布于 2024-09-02 21:03:59 字数 434 浏览 4 评论 0原文

在我正在开发的富客户端 CRUD 框架中,我有一个所谓的编辑面板,顾名思义,它参与通过常用的 swing 输入组件编辑行对象。

现在,面板有一个默认的焦点组件字段,它引用在初始化或清除编辑面板时应接收焦点的输入字段。问题是执行焦点请求的方法的最合逻辑的名称。

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

编辑面板扩展了 JPanel,因此它覆盖了现已弃用的 JComponent 方法。我目前用来避免这种情况的方法名称是 setDefaultFocus()。这听起来不太正确,尽管我将能够忍受它,以防问题的答案出现是一个响亮的

那么,您对重写此类已弃用的方法有何想法?

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 able 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅一夜美梦 2024-09-09 21:03:59

我不会推荐它。无法阻止您的代码发出弃用警告。这让人看起来好像有什么问题。开发人员需要时间来验证这些警告是否是虚假的。

setInitialFocus()怎么样?

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()?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文