稍长一点的答案是:使用setSize()如果组件的父级没有布局管理器,并且setPreferredSize()及其相关setMinimumSize和setMaximumSize如果是的话。setSize()如果组件的父级使用布局管理器,则可能不会做任何事情;这通常会产生影响的位置将位于顶层组件(JFrames和JWindows)和里面的东西scrolled panes..你也必须打电话给setSize...
setSize()、setPreferredSize()都可以设置组件的大小,但二者的使用有所不同。 1、setSize()的使用方式 setSize(int width,int height) setSize(Dimension d) 2、setPreferredSize()的使用方式 setSize(Dimension d) setPreferredSize()是设置首选尺寸。一般情况下: 如果该组件受布局管理器管理(使用默认的也算),需...
1、setPreferredSize需要在使用布局管理器的时候使用,布局管理器会获取空间的preferredsize,因而可以生效。例如borderlayout在north中放入一个panel,panel的高度可以通过这样实现:panel.setPreferredSize(new Dimension(0, 100));这样就设置了一个高度为100的panel,宽度随窗口变化。2、setSize,setLocation,setBounds方法需要在...
简单的回答是:这很复杂。 稍长一点的答案是:使用setSize()如果组件的父级没有布局管理器,并且setPreferredSize()及其相关setMinimumSize和setMaximumSize如果是的话。 setSize()如果组件的父级使用布局管理器,则可能不会做任何事情;这通常会产生影响的位置将位于顶层组件(JFrames和JWindows)和里面的东西scrolled panes...
setPreferredSize(new Dimension(250, 145)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); 代码使用默认构造函数创建编辑窗格,然后调用setEditable(false)以防止用户编辑文本。接下来,代码创建URL对象,并使用它调用setPage方法。 setPage方法打开 URL 指向的资源,并确定文本的格式(在示例中为 HTML)。如果...
public voidsetOffScreenBuffer(ImageComponent2Dbuffer) Sets the off-screen buffer for this Canvas3D. The specified image is written into by the Java 3D renderer. The size of the specified ImageComponent determines the size, in pixels, of this Canvas3D--the size inherited from Component is ignore...
//设置其大小以及其选项卡的位置方向 tp.setPreferredSize(newDimension(500, 200)); tp.setTabPlacement(JTabbedPane.TOP); //设置选项卡在容器内的显示形式 tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); jf.setContentPane(tp); jf.setVisible(true); } }...
this.setEnabled(true); 316 window.remove(bar); 317 window.remove(toolBar); 318 window.remove(scrollPane); 319 window.setVisible(false); 320 321 scrollPane.setPreferredSize(new Dimension(100,500)); 322 getContentPane().add(scrollPane,BorderLayout.SOUTH); 323 getContentPane().add(bar,Border...
{ jEditorPane1.setPage(url); history.add(url); historyIndex=history.size()-1;// 返回此列表中的元素数 jEditorPane1.setEditable(false); jEditorPane1.revalidate(); jurl.setMaximumSize(jurl.getPreferredSize()); } catch(Exception ex){ JOptionPane.showMessageDialog(WebBrowser.this,不能打开网页,...
this.setLocation(Const.Frame_X,Const.Frame_Y);//设置框架在屏幕的位置 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭键 } //添加北面的控件 public void addNorthComponent(){ this.input_text.setPreferredSize(new Dimension(200,30));//设置文本框大小 ...