Article View: borland.public.jbuilder.java.swing
Article #17Problems with XYLayout
From: Don Meredith
Date: Thu, 17 Sep 1998 00:00
Date: Thu, 17 Sep 1998 00:00
93 lines
3222 bytes
3222 bytes
I have come across a problem using the XYLayout control that I was
wondering if anybody else has come across. The problem occurs that when
I add an object to a Panel and initially set it to be invisible
(setVisible to false) that I cannot redisplay this object. If I
initially set it to visible then I can toggle its "viewability" as often
as I like. I hope that it is something that I am fundamentally missing,
but it does not appear to be so, because if I change the layout of the
panel to be GridLayout then everything works as expected.
The source code that demonstrates this is attached below: (if you
change the isViewable in MyClass1 to true the expected behavior occurs,
otherwise I can never get jButton2 to be visible)
Frame1.java:
package untitled2;
import java.awt.*;
import com.sun.java.swing.*;
import java.awt.event.*;
import borland.jbcl.layout.*;
public class Frame1 extends JFrame {
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
XYLayout xYLayout2 = new XYLayout();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public Frame1() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout2);
this.setSize(600, 500);
jPanel1.setAutoscrolls(true);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setText("jButton2");
jPanel1.setLayout(xYLayout1);
jButton2.setVisible(MyClass1.isViewable);
this.getContentPane().add(jPanel1, new XYConstraints(28, 29, 355,
252));
jPanel1.add(jButton1, new XYConstraints(159, 160, 92, 32));
jPanel1.add(jButton2, new XYConstraints(148, 112, 132, 37));
}
void jButton1_actionPerformed(ActionEvent e) {
MyClass1.isViewable = !MyClass1.isViewable;
repaint();
}
public void repaint()
{
jButton2.setVisible(MyClass1.isViewable);
super.repaint();
}
}
MyClass1.java:
package untitled2;
import java.awt.*;
import java.awt.event.*;
public class MyClass1 {
static boolean isViewable = false;
public MyClass1() {
}
public static void main(String[] args) {
Frame1 frame = new Frame1();
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
Technical Details
Message-ID:
<360116DA.91F4F95B@yahoo.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,3a8c8691164a588d X-Google-Attributes: gid111d45,public X-Google-Thread: 109107,3a8c8691164a588d X-Google-Attributes: gid109107,public From: Don Meredith <dmeredith@yahoo.com> Subject: Problems with XYLayout Date: 1998/09/17 Message-ID: <360116DA.91F4F95B@yahoo.com> X-Deja-AN: 392051324 Content-Transfer-Encoding: 7bit Organization: Another Netscape Collabra Server User Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing,borland.public.jbuilder.compiler