Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

View Poll Results: getteng next panel after minimizing and maximizing the window only why?

Voters
0. You may not vote on this poll
  • why o/p is seen after minimizing window??

    0 0%
  • why o/p is seen after minimizing window??

    0 0%
Results 1 to 7 of 7

Thread: dynamically adding panels...but getteng next panel after minimizing and maximizing the window only why?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default dynamically adding panels...but getteng next panel after minimizing and maximizing the window only why?

    import javax.swing.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    class sacreate extends JFrame implements ActionListener
    {
     
    JLabel l1,l2,l3,l4,a,b,c;
    Container pane;
    JPanel p1,p2,p3;
    JTextField t1;
    JComboBox c1,c2;
    JCheckBox m1;
    JButton b1,b2,b3;
    public sacreate()
    {
    try
    {
    pane=getContentPane();
    l1=new JLabel("FieldName"); 
    a=new JLabel("                                       ");
    l2=new JLabel("DataType");
    b=new JLabel("                 ");
    l3=new JLabel("NotNull");
    c=new JLabel("        ");
    l4=new JLabel("Null");
    t1=new JTextField(15);
    c1=new JComboBox();
    c1.addItem("VARCHAR");
    c1.addItem("INTEGER");
    c1.addItem("CHARACTER");
    c2=new JComboBox();
    c2.addItem("PrimaryKey");
    c2.addItem("ForignKey");
    m1=new JCheckBox();
    b3=new JButton("Done");
    b1=new JButton("+");
    b2=new JButton("-");
    p1=new JPanel();
    p2=new JPanel();
    p3=new JPanel();
    p1.add(l1);
    p1.add(a);
    p1.add(l2);
    p1.add(b);
    p1.add(l3);
    p1.add(c);
    p1.add(l4);
    p2.add(t1);
    p2.add(c1);
    p2.add(c2);
    p2.add(m1);
    p2.add(b3);
    p2.add(b1);
    p2.add(b2);
    p3.add(p1);
    p3.add(p2);
    pane.add(p3);
    p1.setLayout(new FlowLayout(FlowLayout.LEFT));
    p2.setLayout(new FlowLayout(FlowLayout.LEFT));
    p3.setLayout(new BorderLayout());
    p3.add(p1,BorderLayout.NORTH);
    p3.add(p2,BorderLayout.SOUTH);
    setLayout(new FlowLayout());
    b1.addActionListener(this);
    b2.addActionListener(this);
    }
    catch(Exception e)
    {
    System.out.println(e.toString());
    }
    }
    public void actionPerformed(ActionEvent ae)
      {
    JPanel p = new JPanel();
    Dimension size=p.getSize();
    System.out.println(size);
    p.setPreferredSize(new Dimension(1600,35));
    JTextField t=new JTextField(15);
    JComboBox m=new JComboBox();
    m.addItem("VARCHAR");
    m.addItem("INTEGER");
    m.addItem("CHARACTER");
    JComboBox n=new JComboBox();
    n.addItem("PrimaryKey");
    n.addItem("ForignKey");
    JCheckBox c=new JCheckBox();
    JButton o=new JButton("Done");
    JButton r=new JButton("+");/*after pressing this '+' button i have to get next panel with some components but by clicking '+' and by minimizing and maximizing the window only i am able to see the next panel why?*/
    r.addActionListener(this);
    JButton q=new JButton("-");
    q.addActionListener(this);
    if(ae.getActionCommand()=="+")
     {
    pane.add(p);
    p.add(t);
    p.add(m);
    p.add(n);
    p.add(c);
    p.add(o);
    p.add(r);
    p.add(q);
    p.revalidate(); 
    p.setLayout(new FlowLayout());
    }
    if(ae.getActionCommand()=="-")
    {
    /*p.remove(t);
    p.remove(m);
    p.remove(n);
    p.remove(c);
    p.remove(o);
    p.remove(r);
    p.remove(q);*/
     
    pane.remove(p);
    pane.revalidate();
    pane.repaint();
    }
    }
    public static void main(String args[])
    {
    sacreate a=new sacreate();
    a.setSize(300,300);
    a.setVisible(true);
    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    a.setLocationRelativeTo(null);
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dynamically adding panels...but getteng next panel after minimizing and maximizing the window only why?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: dynamically adding panels...but getteng next panel after minimizing and maximizing the window only why?

    thanx for saying i did it...

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: dynamically adding panels...but getteng next panel after minimizing and maximizing the window only why?

    I'd recommend posting an SSCCE (see my signature) to demonstrate your problem more clearly, as well as describing your problem more clearly. Further, although you added code tags the indentation makes it quite hard for any human to read. Comments on your code: a) why the try/catch in the constructor? b) don't use == to compare strings, use the equals method. c) I'd recommend reading about java code conventions

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: dynamically adding panels...but getteng next panel after minimizing and maximizing the window only why?

    i kept try catch blocks to caught the errors if any.....if it is removed also there will be no errors...but if == is not kept i am getting an error...= is used for assigning a value and where as == is used to compare to values....

  6. #6
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: dynamically adding panels...the hope the code is help ful to you....

     
    import javax.swing.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    class sacreate extends JFrame implements ActionListener
    {
     
    JLabel l1,l2,l3,l4,a,b,c;
    Container pane;
    JPanel p1,p2,p3;
    JTextField t1;
    JComboBox c1,c2;
    JCheckBox m1;
    JButton b1,b2,b3;
    public sacreate()
    {
     
    pane=getContentPane();
    l1=new JLabel("FieldName"); 
    a=new JLabel("                                       ");
    l2=new JLabel("DataType");
    b=new JLabel("                 ");
    l3=new JLabel("NotNull");
    c=new JLabel("        ");
    l4=new JLabel("Null");
    t1=new JTextField(15);
    c1=new JComboBox();
    c1.addItem("VARCHAR");
    c1.addItem("INTEGER");
    c1.addItem("CHARACTER");
    c2=new JComboBox();
    c2.addItem("PrimaryKey");
    c2.addItem("ForignKey");
    m1=new JCheckBox();
    b3=new JButton("Done");
    b1=new JButton("+");
    b2=new JButton("-");
    p1=new JPanel();
    p2=new JPanel();
    p3=new JPanel();
    p1.add(l1);
    p1.add(a);
    p1.add(l2);
    p1.add(b);
    p1.add(l3);
    p1.add(c);
    p1.add(l4);
    p2.add(t1);
    p2.add(c1);
    p2.add(c2);
    p2.add(m1);
    p2.add(b3);
    p2.add(b1);
    p2.add(b2);
    p3.add(p1);
    p3.add(p2);
    pane.add(p3);
    p1.setLayout(new FlowLayout(FlowLayout.LEFT));
    p2.setLayout(new FlowLayout(FlowLayout.LEFT));
    p3.setLayout(new BorderLayout());
    p3.add(p1,BorderLayout.NORTH);
    p3.add(p2,BorderLayout.SOUTH);
    setLayout(new FlowLayout());
    b1.addActionListener(this);
    b2.addActionListener(this);
    }
     
     
     
    public void actionPerformed(ActionEvent ae)
      {
     
     JTextField t;
     JComboBox m,n;
     JCheckBox c;
     JButton o,r,q;
     JPanel p;
    p = new JPanel();
    Dimension size=p.getSize();
    System.out.println(size);
    p.setPreferredSize(new Dimension(1600,35));
    t=new JTextField(15);
    m=new JComboBox();
    m.addItem("VARCHAR");
    m.addItem("INTEGER");
    m.addItem("CHARACTER");
    n=new JComboBox();
    n.addItem("PrimaryKey");
    n.addItem("ForignKey");
    c=new JCheckBox();
    o=new JButton("Done");
    r=new JButton("+");
    r.addActionListener(this);
    q=new JButton("-");
    q.addActionListener(this);
    if(ae.getActionCommand()=="+")
    {
    pane.add(p);
    p.add(t);
    p.add(m);
    p.add(n);
    p.add(c);
    p.add(o);
    p.add(r);
    p.add(q);
    p.revalidate(); 
    p.setLayout(new FlowLayout());
    }
    }
    public static void main(String args[]) 
    {
     
    SwingUtilities.invokeLater(new Runnable() 
    {
    public void run() 
    {
    sacreate a=new sacreate();
    a.setSize(1600,800);
    a.setVisible(true);
    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    a.setLocationRelativeTo(null);
    }
    });
    }
    }

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dynamically adding panels...but getteng next panel after minimizing and maximizing the window only why?

    Please edit your post and properly format the code. It needs indentation for code within {}s.
    All statements should NOT start in the first column.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. adding or removing panels to panels
    By luisp88 in forum AWT / Java Swing
    Replies: 3
    Last Post: November 1st, 2011, 04:37 PM
  2. Adding a Panel from a different class
    By DudeJericho in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 25th, 2011, 07:28 AM
  3. Adding strings to an array dynamically, how can i do it?
    By emkoirl in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 8th, 2011, 02:07 PM
  4. [???]basic question on frame window panel
    By Codeguess in forum AWT / Java Swing
    Replies: 1
    Last Post: January 12th, 2011, 08:03 AM
  5. Adding panels to a central panel.
    By Johannes in forum AWT / Java Swing
    Replies: 3
    Last Post: July 4th, 2010, 05:31 PM