R
Ryan Stewart
I've looked around the web and Sun's bug DB, but don't seem to see any direct
mention of this problem. I came across it at work today (somebody flagged me
down with one of those, "What do you think about..." questions). It was quite
puzzling at first due to some other code cluttering it. Here is the simple
version:
import javax.swing.JFrame;
import javax.swing.BoxLayout;
public class BoxLayoutBug {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setLayout(new BoxLayout(frame, BoxLayout.PAGE_AXIS));
frame.pack();
}
}
Run that and you'll get a java.awt.AWTError with message "BoxLayout can't be
shared". Why? The container passed to the BoxLayout must be the same container
on which the Layout is set. The above code causes the BoxLayout to be set on the
JFrame's contentPane, though the layout is referencing the frame. This is due to
JFrame's the overriden behavior of the setLayout method in 1.5. Would you
consider this a bug worthy of reporting? It seems that you have to have
knowledge of JFrame's internal workings in order to figure this out, so there's
at least a flaw in the interface.
mention of this problem. I came across it at work today (somebody flagged me
down with one of those, "What do you think about..." questions). It was quite
puzzling at first due to some other code cluttering it. Here is the simple
version:
import javax.swing.JFrame;
import javax.swing.BoxLayout;
public class BoxLayoutBug {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setLayout(new BoxLayout(frame, BoxLayout.PAGE_AXIS));
frame.pack();
}
}
Run that and you'll get a java.awt.AWTError with message "BoxLayout can't be
shared". Why? The container passed to the BoxLayout must be the same container
on which the Layout is set. The above code causes the BoxLayout to be set on the
JFrame's contentPane, though the layout is referencing the frame. This is due to
JFrame's the overriden behavior of the setLayout method in 1.5. Would you
consider this a bug worthy of reporting? It seems that you have to have
knowledge of JFrame's internal workings in order to figure this out, so there's
at least a flaw in the interface.