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.

Results 1 to 7 of 7

Thread: GUI problem

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default GUI problem

    I created a GUI that extends JFrame. The GUI has several textfields, buttons, labels and lists. The problem arises when i minimise the window and then maximise it. The textfields stay in place but the list, labels and buttons stick to the top of the window after maximising! Please Help
    this is the part of the code where i add a list, label and button for example:

      l = new List();
                                                       l.setSize(250, 200);
     
                                                       l.setLocation(500, 250);
                                                       l.setVisible(true);
                                                       l.setFocusable(true);
                                                       M.add(l);//was M
                                                       l.setFont(new Font("sansserif", Font.BOLD, 15));//set the txt font n size
     
                                                       patientListTitle=new Label("PID:         Patient's Name:");
                                                       patientListTitle.setSize(200, 50);
     
                                                       patientListTitle.setLocation(500, 200);
                                                       patientListTitle.setForeground(Color.BLACK);
                                                       patientListTitle.setBackground(Color.white);
                                                       patientListTitle.setVisible(true);
                                                       patientListTitle.setFocusable(true);
     
                                                      M.add(patientListTitle);//was M
     
     
                                                       Select.setSize(50, 25);
                                                       Select.setLocation(500, 580);
                                                       Select.setVisible(true);
                                                       Select.setFocusable(true);
                                                       M.add(Select);//was M
     
                                                       Select.addActionListener(new ActionListener(){
                                                        public void actionPerformed(ActionEvent e) {
                                                                    System.out.println("Select Button clicked");
                                                                    // ADD STUFF HERE :D
     
                                                                    getIndexedItem=l.getItem(l.getSelectedIndex());
                                                                    System.out.println(getIndexedItem);
                                        try {
                                            deletePatient(getIndexedItem, l.getSelectedIndex());
                                        } catch (SQLException ex) {
                                            Logger.getLogger(javaapplication2.class.getName()).log(Level.SEVERE, null, ex);
                                        } catch (ClassNotFoundException ex) {
                                            Logger.getLogger(javaapplication2.class.getName()).log(Level.SEVERE, null, ex);
                                        }
     
     
                                                                }
                                                        });
                                                      repaint();
                                try {
                                    retrievePatient();
                                } catch (SQLException ex) {
                                    Logger.getLogger(javaapplication2.class.getName()).log(Level.SEVERE, null, ex);
                                }
     
                                                                               repaint();


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: GUI problem

    Is this:
    l = new List();
    supposed to be a JList?

    If you really want to use coordinates, I would suggest the layout I made. I attached text documents of the java classes (since I cannot attach .java files). Save them as .java files instead of .txt files, compile them, and run them to see how it works. Very simple once you get the hang of it.

    All I ask is that you don't claim it as your creation.

    There are a few "bugs" in it, as in some of the methods don't work exactly as expected and some are incomplete. If you feel like completing them or fixing them, tell me and I'll add you on the credit if you get them working.
    Attached Files Attached Files
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

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

    Default Re: GUI problem

    With the information provided it is difficult to ascertain what the exact problem is, but my guess is along the same lines as aussiemcgr. Are you setting your layout to null? If so, do not use this approach. Use a standard layout that Swing provides. See A Visual Guide to Layout Managers

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: GUI problem

    Thank you all. What I am doing is that i created a public class that extends Jpannel and I am adding my components to it. It works perfectly before minimising the window:

    after minmising the window:

    I did not use any grids or layout organizations. Just added the components and set the coordinates. Is that the problem?

  5. #5
    Junior Member
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: GUI problem

    list is not a Jlist.

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: GUI problem

    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: GUI problem

    Quote Originally Posted by Reem View Post
    list is not a Jlist.
    Well then I'm confused. The List class (List (Java Platform SE 6)) has no setSize method, setLocation method, setVisible method, setFocusable method, or setFont method. The JList class however (JList (Java Platform SE 6)) has all of those.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/