Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JSeparator line invisible

268 views
Skip to first unread message

sv...@my-deja.com

unread,
Jan 19, 2001, 1:49:17 AM1/19/01
to
Hi All,

I am trying to write an extension of a JPanel in which a Button
and two checkboxes are laid out in a horizontal plane and a line
connects the button and check boxes. I tried to implement the line by
using JSeparator. The problem is Jseparator is invisible... The code
shown below produces a button and 2 checkboxes lined up but with no
line between them.
Any ideas as to why the Jseparator is invisible ?

Thanks in advance

===============================================
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;

import java.text.SimpleDateFormat;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.JTable;
import javax.swing.JCheckBox;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.border.*;

public class MyPanel extends JPanel
{
private JButton nodeButton;
private JLabel label1 = new JLabel("Label1");
private JLabel label2 = new JLabel("Label2");

private JCheckBox checkBox1;
private JCheckBox checkBox2;


public MyPanel(JFrame frame)
{
//this.frame = frame;
initScreen();
}
private void initScreen()
{
JLabel nodeLabel = new JLabel("Label1");
nodeButton = new JButton("Node");
checkBox1 = new JCheckBox();
checkBox2 = new JCheckBox();

JSeparator hs = new JSeparator(JSeparator.HORIZONTAL);
hs.setSize(3,6);
hs.setForeground(Color.blue);
hs.setBackground(Color.white);
hs.setBorder(new LineBorder(Color.black,20));
hs.setVisible(true);

setLayout(new GridBagLayout());
setBorder(new BevelBorder(BevelBorder.RAISED));

GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();

gbc.insets = new Insets(1, 1, 1, 1);

gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
add(new JLabel(""),gbc);

gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.weightx = 0.0;
gbc.weighty = 1.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.VERTICAL;
add(new JSeparator(JSeparator.HORIZONTAL),gbc);

gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
add(new JLabel(""),gbc);

gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridheight = 3;
gbc.gridwidth = 2;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
add(nodeButton,gbc);

gbc.gridx = 3;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.gridwidth = 6;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.NONE;
add(label1,gbc);

gbc.gridx = 3;
gbc.gridy = 1;
gbc.gridheight = 1;
gbc.gridwidth = 6;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.VERTICAL;
add(new JSeparator(JSeparator.HORIZONTAL),gbc);

gbc.gridx = 3;
gbc.gridy = 2;
gbc.gridheight = 1;
gbc.gridwidth =6;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
add(new JLabel(""),gbc);

gbc.gridx = 9;
gbc.gridy = 0;
gbc.gridheight = 3;
gbc.gridwidth = 2;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.VERTICAL;
add(checkBox1,gbc);

gbc.gridx = 11;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.gridwidth = 6;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.NONE;
add(label2,gbc);

gbc.gridx = 11;
gbc.gridy = 1;
gbc.gridheight = 1;
gbc.gridwidth = 6;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.VERTICAL;
add(new JSeparator(JSeparator.HORIZONTAL),gbc);

gbc.gridx = 11;
gbc.gridy = 2;
gbc.gridheight = 1;
gbc.gridwidth =6;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
add(new JLabel(""),gbc);

gbc.gridx = 17;
gbc.gridy = 0;
gbc.gridheight = 3;
gbc.gridwidth = 2;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.VERTICAL;
add(checkBox2,gbc);

}
}
========================================


Sent via Deja.com
http://www.deja.com/

Julian Perrott

unread,
Jan 19, 2001, 7:56:56 PM1/19/01
to
If you set the preffered size of the JSeparator it will become
visible, but at the top of the area.

Julian.

gbc.gridx = 3;
gbc.gridy = 1;
gbc.gridheight = 1;
gbc.gridwidth = 6;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.VERTICAL;

JSeparator j=new JSeparator(JSeparator.HORIZONTAL);
j.setPreferredSize(new java.awt.Dimension (69,69));
add(j,gbc);

0 new messages