this is my code, the only problem I'm facing is that the jseperator is not appearing!

 import java.awt.event.*;
 import java.util.*;
 import javax.swing.*;
 import java.awt.*;

public class AdmForm extends JFrame{
Container con1= getContentPane();
Container con2=getContentPane();
    JFrame f2= new JFrame();
    JButton b1= new JButton("Click me!");
    JSeparator sep= new JSeparator(SwingConstants.HORIZONTAL);

    AdmForm(){
    setSize(300,300);
    setLayout(null);
    b1.setBounds(60,60,100,40);
    sep.setLocation(60,130);
    sep.setPreferredSize(new Dimension(10,1));
    add(sep);
    con1.add(b1);
    f2.setSize(300,300);
    f2.setLayout(null);
    setVisible(true);

    b1.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
        f2.setVisible(true);
            }});


    }


    public static void main(String[] args) {

        new AdmForm();
        System.out.println("Hello World!");
    }
}

You are using a null layout manager for some reason - I suppose you are aware that this kills your portability - as soon as you run the code on any other machine with a different screen res / font size your text won't fit properly.

Anyway, getPreferredSize is called by layout managers to help lay out the screen as closely as possible to your requirements. With a null manager setting a preferred size is useless.
If you must use a null layout manager then you have to setBounds for every component.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.