GWT 在浏览器窗口调整大小时调整组件大小
我在绝对面板中放置了许多小部件,并将绝对面板添加到 RootLayoutPanel 中。但是在浏览器调整大小时,内容没有调整大小......我错过了什么吗???
package panelDemo.client;
import com.google.gwt.user.client.ui.AbsolutePanel;
public class AbsolutePanelDemo extends Composite{
public AbsolutePanelDemo() {
AbsolutePanel absolutePanel = new AbsolutePanel();
initWidget(absolutePanel);
absolutePanel.setSize("1024px", "768px");
TextBox txtbox = new TextBox();
txtbox.setReadOnly(true);
txtbox.setText("Enter Something");
absolutePanel.add(txtbox);
Label lblIsValid = new Label("Label:");
absolutePanel.add(lblIsValid, 192, 10);
CheckBox chckbxIsValid = new CheckBox("label");
absolutePanel.add(chckbxIsValid, 244, 10);
chckbxIsValid.setSize("76px", "19px");
Label lblAssignedUser = new Label("Assigned User:");
absolutePanel.add(lblAssignedUser, 362, 13);
TextBox user = new TextBox();
user.setReadOnly(true);
user.setText("xyz");
absolutePanel.add(user, 457, 1);
Button btnClickMeText = new Button("Click Me Text");
absolutePanel.add(btnClickMeText, 646, 1);
btnClickMeText.setSize("100px", "28px");
Label lblAlert = new Label("Alert:");
absolutePanel.add(lblAlert, 113, 48);
TextBox txtbxAlert = new TextBox();
txtbxAlert.setText("Alert");
absolutePanel.add(txtbxAlert, 161, 36);
txtbxAlert.setSize("140px", "16px");
Label lblExpires = new Label("Expires:");
absolutePanel.add(lblExpires, 99, 93);
DateBox dateBox = new DateBox();
absolutePanel.add(dateBox, 161, 81);
Label lblPriority = new Label("Priority:");
absolutePanel.add(lblPriority, 99, 133);
ListBox comboBox = new ListBox();
absolutePanel.add(comboBox, 161, 127);
comboBox.setSize("150px", "22px");
Label lblGender = new Label("Gender:");
absolutePanel.add(lblGender, 405, 48);
RadioButton rdbtnMale = new RadioButton("new name", "Male");
absolutePanel.add(rdbtnMale, 457, 45);
RadioButton rdbtnFemale = new RadioButton("new name", "Female");
absolutePanel.add(rdbtnFemale, 457, 70);
Label lblDescription = new Label("Description:");
absolutePanel.add(lblDescription, 386, 114);
TextArea txtrThisIsSome = new TextArea();
txtrThisIsSome.setText("This is some description");
absolutePanel.add(txtrThisIsSome, 457, 118);
txtrThisIsSome.setSize("149px", "88px");
Label lblContact = new Label("Contact:");
absolutePanel.add(lblContact, 95, 171);
IntegerBox integerBox = new IntegerBox();
integerBox.setText("91");
integerBox.setVisibleLength(2);
absolutePanel.add(integerBox, 161, 165);
IntegerBox integerBox_1 = new IntegerBox();
integerBox_1.setVisibleLength(10);
absolutePanel.add(integerBox_1, 203, 165);
FileUpload fileUpload = new FileUpload();
fileUpload.setTitle("Upload Something");
absolutePanel.add(fileUpload, 161, 194);
Label lblUpload = new Label("Upload:");
absolutePanel.add(lblUpload, 99, 200);
Button btnSave = new Button("Save");
absolutePanel.add(btnSave, 290, 255);
btnSave.setSize("100px", "28px");
Button btnCancel = new Button("Cancel");
absolutePanel.add(btnCancel, 457, 255);
btnCancel.setSize("100px", "28px");
HTMLPanel panel = new HTMLPanel("This is just an example to show that in absolute panel resize wont work. This is evident if you resize your browser window.");
absolutePanel.add(panel, 10, 319);
}
}
我的 onModuleLoad 函数如下所示
public void onModuleLoad() {
RootLayoutPanel.get().add(new AbsolutePanelDemo());
}
I have placed many widgets in the absolute panel and added the absolute panel to the RootLayoutPanel. But on Browser resize, the contents are not resizing... am i missing something???
package panelDemo.client;
import com.google.gwt.user.client.ui.AbsolutePanel;
public class AbsolutePanelDemo extends Composite{
public AbsolutePanelDemo() {
AbsolutePanel absolutePanel = new AbsolutePanel();
initWidget(absolutePanel);
absolutePanel.setSize("1024px", "768px");
TextBox txtbox = new TextBox();
txtbox.setReadOnly(true);
txtbox.setText("Enter Something");
absolutePanel.add(txtbox);
Label lblIsValid = new Label("Label:");
absolutePanel.add(lblIsValid, 192, 10);
CheckBox chckbxIsValid = new CheckBox("label");
absolutePanel.add(chckbxIsValid, 244, 10);
chckbxIsValid.setSize("76px", "19px");
Label lblAssignedUser = new Label("Assigned User:");
absolutePanel.add(lblAssignedUser, 362, 13);
TextBox user = new TextBox();
user.setReadOnly(true);
user.setText("xyz");
absolutePanel.add(user, 457, 1);
Button btnClickMeText = new Button("Click Me Text");
absolutePanel.add(btnClickMeText, 646, 1);
btnClickMeText.setSize("100px", "28px");
Label lblAlert = new Label("Alert:");
absolutePanel.add(lblAlert, 113, 48);
TextBox txtbxAlert = new TextBox();
txtbxAlert.setText("Alert");
absolutePanel.add(txtbxAlert, 161, 36);
txtbxAlert.setSize("140px", "16px");
Label lblExpires = new Label("Expires:");
absolutePanel.add(lblExpires, 99, 93);
DateBox dateBox = new DateBox();
absolutePanel.add(dateBox, 161, 81);
Label lblPriority = new Label("Priority:");
absolutePanel.add(lblPriority, 99, 133);
ListBox comboBox = new ListBox();
absolutePanel.add(comboBox, 161, 127);
comboBox.setSize("150px", "22px");
Label lblGender = new Label("Gender:");
absolutePanel.add(lblGender, 405, 48);
RadioButton rdbtnMale = new RadioButton("new name", "Male");
absolutePanel.add(rdbtnMale, 457, 45);
RadioButton rdbtnFemale = new RadioButton("new name", "Female");
absolutePanel.add(rdbtnFemale, 457, 70);
Label lblDescription = new Label("Description:");
absolutePanel.add(lblDescription, 386, 114);
TextArea txtrThisIsSome = new TextArea();
txtrThisIsSome.setText("This is some description");
absolutePanel.add(txtrThisIsSome, 457, 118);
txtrThisIsSome.setSize("149px", "88px");
Label lblContact = new Label("Contact:");
absolutePanel.add(lblContact, 95, 171);
IntegerBox integerBox = new IntegerBox();
integerBox.setText("91");
integerBox.setVisibleLength(2);
absolutePanel.add(integerBox, 161, 165);
IntegerBox integerBox_1 = new IntegerBox();
integerBox_1.setVisibleLength(10);
absolutePanel.add(integerBox_1, 203, 165);
FileUpload fileUpload = new FileUpload();
fileUpload.setTitle("Upload Something");
absolutePanel.add(fileUpload, 161, 194);
Label lblUpload = new Label("Upload:");
absolutePanel.add(lblUpload, 99, 200);
Button btnSave = new Button("Save");
absolutePanel.add(btnSave, 290, 255);
btnSave.setSize("100px", "28px");
Button btnCancel = new Button("Cancel");
absolutePanel.add(btnCancel, 457, 255);
btnCancel.setSize("100px", "28px");
HTMLPanel panel = new HTMLPanel("This is just an example to show that in absolute panel resize wont work. This is evident if you resize your browser window.");
absolutePanel.add(panel, 10, 319);
}
}
And my onModuleLoad function looks like this
public void onModuleLoad() {
RootLayoutPanel.get().add(new AbsolutePanelDemo());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
并非所有小部件都可以使用 RootLayoutPanel(以及其他 *LayoutPanel)的自动调整大小功能 - 只有实现
RequiresResize
的小部件才会在其父级更改大小时收到通知,并且它们必须更新。CellBrowser
和DataGrid
是 GWT 中支持此功能的两个小部件,所有以 LayoutPanel 结尾的容器也都支持它。另外两个是HeaderPanel
和ResizeComposite
。您可以通过实现接口并将调用传递给可以处理新尺寸的另一个小部件,或者通过为您需要的行为构建您自己的调整大小代码来创建自己的尺寸。Not all widgets can use RootLayoutPanel's (and the other *LayoutPanel's) automatic resizing stuff - only widgets that implement
RequiresResize
will be notified when their parent has changed size, and they must update.CellBrowser
andDataGrid
are two widgets in GWT that support this, all of the containers that end in LayoutPanel support it as well. Two others areHeaderPanel
andResizeComposite
. You can create your own by implementing the interface and either passing the call along to another widget that can handle a new size, or by building your own resize code for the behavior you need.您使用的是
AbsolutePanel
,它将其小部件放置在绝对位置上。据我所知,这也意味着除了绝对定位(当您调整面板或浏览器大小时,它们也不会改变其位置)之外,它们的尺寸也是绝对的(因此,如果您调整浏览器大小,它们的大小也不会改变) )。该问题最简单的解决方案是使用另一个面板,
FlowPanel
进行简单测试(创建大量div
)或更奇特的东西,例如CellPanel< /code>、
HorizontalPanel
、VerticalPanel
...不过,不要过度使用这些面板,它们会占用相当多的浏览器资源,因为它们往往会创建巨大的 html 表;)。更困难的解决方案是实现 Window.addResizeHandler() 并自行调整 AbsolutePanel 中小部件的所有大小。
You're using an
AbsolutePanel
which positions its widgets on an absolute position. As far as I know this also means that apart from being positioned absolute (they will also not change their position when you resize the panel, or the browser) their dimension also is absolute (so their size will also not change if you resize your browser).Easiest solution to the problem would be the use of another panel,
FlowPanel
for a simple test (creates a lot ofdiv
s) or something more fancy likeCellPanel
,HorizontalPanel
,VerticalPanel
... Don't overuse those panels though, they take up quite some browser resources as they tend to create huge html tables ;).More difficult solution is to implement
Window.addResizeHandler()
and do all the resizing of the widgets in your AbsolutePanel yourself.尝试为面板设置布局,例如 BorderLAyout
Try setting Layout for your Panel such as BorderLAyout