4753342: thành phần cấp cao nhất của Swing nên chuyển hướng thêm/xóa phương pháp để ContentPane
Mô tả:
Trái ngược với lập trình AWT, JFrame
/JDialg
/JWindow
/JApplet
/JInternalFrame
không cho phép bạn thêm Component
s vào nó, thay vào đó bạn phải tìm hiểu về JRootPane
và thêm trẻ em Component
s cho nó. Điều này làm tăng thêm sự nhầm lẫn không cần thiết cho các nhà phát triển mới .
Trước 5.0, cố gắng thêm hoặc xóa Component
từ một trong số các cấp cao nhất Component
s này sẽ dẫn đến ngoại lệ. Trong 5.0, sẽ không có ngoại lệ nào được ném, thay vào đó, Component
sẽ được thêm hoặc xóa khỏi ngăn nội dung. Điều này dẫn đến một số sửa đổi đến javadoc của JFrame
, JDialog
, JWindow
, JApplet
và JInternalFrame
. Điều này đã được tóm tắt trong javadoc RootPaneContainer của:
* For conveniance
* <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>,
* <code>JApplet</code> and <code>JInternalFrame</code>, by default,
* forward all calls to <code>add</code> and its variants,
* <code>remove</code> and <code>setLayout</code> to the
* <code>contentPane</code>. This means rather than writing:
* <pre>
* rootPaneContainer.getContentPane().add(component);
* </pre>
* you can do:
* <pre>
* rootPaneContainer.add(component);
* </pre>
* <p>
* The behavior of <code>add</code> and its variants and
* <code>setLayout</code> for
* <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>,
* <code>JApplet</code> and <code>JInternalFrame</code> is controlled by
* the <code>rootPaneCheckingEnabled</code> property. If this property is
* true, the default, then <code>add</code> and its variants and
* <code>setLayout</code> are
* forwarded to the <code>contentPane</code>, if it is false, then these
* methods operate directly on the <code>RootPaneContainer</code>. This
* property is only intended for subclasses, and is therefor protected.
lý do tôi cho hỏi là tôi đang giảng dạy Giới thiệu về CS và các ví dụ trong cuốn sách đều sử dụng ký pháp cũ.Tôi muốn có thể cung cấp cho sinh viên một số lý do tại sao nó đã từng cần thiết để làm thêm bước. –