JPanel 居然有这样的方法: add(bt,"abc"); bt是按钮对象引用。不解中。。

sure2003 2008-10-15 12:13:41
我查手册和源码,还是无法找到这个函数原型。。。
...全文
226 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
junjun1984 2008-10-15
  • 打赏
  • 举报
回复
mark 向1~3楼的前辈学习。
ZangXT 2008-10-15
  • 打赏
  • 举报
回复
你的程序代码呢?
cydp007 2008-10-15
  • 打赏
  • 举报
回复
JPanel查不到.. 向上回溯.. 查找父类..

找不到再向上..

总能找到的.
justinavril 2008-10-15
  • 打赏
  • 举报
回复
public void add(Component comp,
Object constraints)
应该是这个方法吧...
lxxzhy 2008-10-15
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 sure2003 的回复:]
这个原型,我是找到了,但是怀疑它不是。
为什么不能直接是:
public void add(Component comp, String name) {...}
[/Quote]
为什么一定要直接是public void add(Component comp, String name) {...}呢?
helei123a 2008-10-15
  • 打赏
  • 举报
回复
public void add(Component comp, Object constraints) {...}
helei123a 2008-10-15
  • 打赏
  • 举报
回复
public void add(Component comp, Object constraints) {...}
sure2003 2008-10-15
  • 打赏
  • 举报
回复
这个原型,我是找到了,但是怀疑它不是。
为什么不能直接是:
public void add(Component comp, String name) {...}
sagezk 2008-10-15
  • 打赏
  • 举报
回复
它超类 java.awt.Container 有,如下
public void add(Component comp, Object constraints) {...}

其中 JButton 间接继承自 Component,String 更不用说了。
overmaker 2008-10-15
  • 打赏
  • 举报
回复
public void add(Component comp,Object constraints)
Adds the specified component to the end of this container. Also notifies the layout manager to add the component to this container's layout using the specified constraints object. This is a convenience method for addImpl(java.awt.Component, java.lang.Object, int).
Note: If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added.


Parameters:
comp - the component to be added
constraints - an object expressing layout contraints for this component
Throws:
NullPointerException - if comp is null
overmaker 2008-10-15
  • 打赏
  • 举报
回复
public void add(Component comp,
Object constraints)Adds the specified component to the end of this container. Also notifies the layout manager to add the component to this container's layout using the specified constraints object. This is a convenience method for addImpl(java.awt.Component, java.lang.Object, int).
Note: If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added.


Parameters:
comp - the component to be added
constraints - an object expressing layout contraints for this component
Throws:
NullPointerException - if comp is null

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧