Home » Eclipse Projects » WindowBuilder » Large applet issues
| Large applet issues [message #875559] |
Tue, 22 May 2012 20:33  |
Marc Chamberlin Messages: 27 Registered: July 2009 |
Junior Member |
|
|
Hello - I am encountering a problem with using WindowBuilder to design
a GUI for large JApplets which I need some help with. My applet is
rather large in size, so to accommodate it, I have extended JPanel with
a variant called SizeableJPanel that simply overrides the
setPreferredSize method to calculate the preferred size based on the
position of all the sub components within it. This then gets wrapped
inside a scrollPane to allow a user to scroll the contents of the
contained SizeableJPanel. This all works just fine, when the applet is
executed, or even when simply tested using the "Quickly
test/preview...." button inside Eclipse/WindowBuilder.
My problem is that WindowBuilder itself does not render the view of the
applet correctly in its editor window. I do not fully grok how
WindowBuilder chooses the "default size" it thinks the applet should be,
but anything that is outside of this default size gets clipped and is
not rendered in the view properly. This makes it very difficult to use
WindowBuilder to layout components in the part of the applet GUI that is
clipped. I have discovered, (trial and error) that setting the default
"form width and height" for Swing does affect this default applet size
but only up to a certain point. Further increases of either of these
values does not affect what WindowBuilder shows for the applet GUI, and
anything beyond that point is clipped out of view, unless a particular
clipped component is directly selected. FWIW my Swing form default
settings is now set to 600x1400 pixels. One guess I might make, and this
is a real long shot, is that it kinda appears that the maximum width and
height of the applet that WindowBuilder will render is based on the
width and height of the screen of the system that Eclipse is running
on??? I note that the applets GUI is being rendered on my desktop
momentarily just before it is displayed in the WindowBuilders edit
window, so hence my guessing there might be some sort of connection, but
as I said, I am really guessing....
I have written a small test applet that illustrates this issue Note
that I am using Absolute layout in the JPanel (panel_1) that is located
at the bottom of the applet and within it there is a button
(btnNewButton_2) that is located in the area that WindowBuilder is
clipping. As one can see, manipulating buttons and other widgets within
the clipped area is difficult.
I am unable to grab any of the boundary lines for the JApplet itself, to
resize it either, which is another issue I do not understand. That seems
like the obvious solution and one I would intuitively expect to be able
to do?
I do not think that the SizeableJPanel container I wrote has anything to
do with this problem. I have tried/tested this without it, and still get
the clipping problem. I simply included it here to give some context
about what I am trying to achieve. Yes, the applet will be larger than
what can be displayed on a screen, hence the need to make it scrollable.
It also doubles as a WebStart app and will have the capability to
"float" in its own window which is again why the ability to scroll it
will be needed. Attached is the code for my SizeableJPanel, and for the
test applet that I have written to demonstrate this problem. Would sure
appreciate any help from kindly gurus who can give me some guidance on
how to control the size of the applet as it is rendered in the
WindowBuilder's editor.
One other question/nit I have - How does one get rid of the
WindowBuilder label and revision number shown in the lower right corner
of the edit area? I have components and widgets in my applet/application
GUIs that those labels sometimes sit on top of, making it again hard to
work with. I didn't see anything in the WindowBuilder preferences that
allow me to turn the display of that info off...
Marc...
P.S.
Version: Indigo Service Release 2
Build id: 20120216-1857
Swing Designer 1.3.0.r37x201202021417
WindowBuilder Core 1.3.0.r37x201202052311
WindowBuilder Core UI 1.3.0.r37x201202052340
> java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
package utilities;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import javax.swing.JPanel;
public class SizeableJPanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
/*
* Finds the smallest rectangle enclosing all this container's components.
* This makes JScrollPane behave correctly when you want put a container in
* it that has a null (absolute) layout.
*/
@Override
public Dimension getPreferredSize() {
int maxX = 0;
int maxY = 0;
Component[] components = this.getComponents();
for (int i = 0; i < components.length; i++) {
Rectangle bounds = components[i].getBounds();
maxX = Math.max(maxX, (int) bounds.getMaxX());
maxY = Math.max(maxY, (int) bounds.getMaxY());
}
return new Dimension(maxX, maxY);
}
}
package Test;
import javax.swing.JApplet;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import utilities.SizeableJPanel;
import java.awt.Dimension;
public class testApplet extends JApplet {
private JScrollPane scrollPane;
private SizeableJPanel panel;
private JButton btnNewButton;
private JButton btnNewButton_1;
private JPanel panel_1;
private JButton btnNewButton_2;
/**
* Create the applet.
*/
public testApplet() {
initGUI();
}
private void initGUI() {
getContentPane().add(getScrollPane_1(), BorderLayout.CENTER);
}
private JScrollPane getScrollPane_1() {
if (scrollPane == null) {
scrollPane = new JScrollPane();
scrollPane.setViewportView(getPanel_2());
}
return scrollPane;
}
private SizeableJPanel getPanel_2() {
if (panel == null) {
panel = new SizeableJPanel();
panel.setLayout(null);
panel.add(getBtnNewButton());
panel.add(getBtnNewButton_1());
panel.add(getPanel_1());
}
return panel;
}
private JButton getBtnNewButton() {
if (btnNewButton == null) {
btnNewButton = new JButton("New button");
btnNewButton.setBounds(51, 56, 107, 25);
}
return btnNewButton;
}
private JButton getBtnNewButton_1() {
if (btnNewButton_1 == null) {
btnNewButton_1 = new JButton("New button");
btnNewButton_1.setBounds(306, 314, 107, 25);
}
return btnNewButton_1;
}
private JPanel getPanel_1() {
if (panel_1 == null) {
panel_1 = new JPanel();
panel_1.setBounds(10, 400, 550, 900);
panel_1.setLayout(null);
panel_1.add(getButton_1());
}
return panel_1;
}
private JButton getButton_1() {
if (btnNewButton_2 == null) {
btnNewButton_2 = new JButton("New button");
btnNewButton_2.setBounds(180, 800, 107, 25);
}
return btnNewButton_2;
}
}
|
|
|
Goto Forum:
Current Time: Tue May 21 06:49:29 EDT 2013
Powered by FUDForum. Page generated in 0.01697 seconds
|