gpt4 book ai didi

java - 为什么JFrame定义的重写的 `add`方法在JFrame的API文档中没有提到?

转载 作者:行者123 更新时间:2023-11-30 07:44:10 24 4
gpt4 key购买 nike

引用http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html :

As a conveniance add and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary. This means you can write:

frame.add(child);

And the child will be added to the contentPane.

引自《Core Java Volume I - Fundamentals》(第 9 版)第 7 章,第 7.4 节。

As of Java SE 5.0, the JFrame.add method has given up trying to reeducate programmers, and simply calls add on the content pane.

Thus, you can simply use the call

frame.add(c);

但是当我滚动浏览 API 文档时 http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html , 我在 JFrame 中找不到有关 add 方法的任何文档重写父类的 add 方法。

事实上,我在此页面中看到的任何 add 方法的第一次出现是在“从类 java.awt.Container 继承的方法”部分中页。

为什么没有提到JFrame定义的重写的add方法在JFrame的API文档中?

最佳答案

add尚未被覆盖,仍然继承自 java.awt.Container但正如您在下面看到的,对 addImpl 进行了调用,该调用在 JFrame 中被覆盖。

376     public Component add(Component comp) {
377 addImpl(comp, null, -1);
378 return comp;
379 }
<小时/>

JFrame#addImpl()

Adds the specified child Component. This method is overridden to conditionally forward calls to the contentPane. By default, children are added to the contentPane instead of the frame, refer to RootPaneContainer for details.

关于java - 为什么JFrame定义的重写的 `add`方法在JFrame的API文档中没有提到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34159151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com