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 3 of 3

Thread: Trouble getting my frame and panels to show up!?!?

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Trouble getting my frame and panels to show up!?!?

    I'm trying to add these two panels to my frame. I want my mainPanel1 to be in the top of my frame and mainPanel2 to be in the bottom. Therefore I thought I'm suppose to set layout to border layout like a did. A frame does display on my screen but there is nothing in it. I tried creating a border line and title thinking that I needed to make the panels visible some way but it's still not working. However, it seems to compile fine without any errors. Any ideas?
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.border.Border;
    import javax.swing.border.LineBorder;
    import javax.swing.border.TitledBorder;
     
    public class resistortests extends javax.swing.JFrame
    {
     
        public resistortests()
        {
     
            JPanel mainPanel1 = new JPanel(new BorderLayout());
            //mainPanel1.setLayout(new BorderLayout());
            mainPanel1.setBorder(new TitledBorder("mainPanel1"));
     
            JPanel mainPanel2 = new JPanel(new GridLayout());
            //mainPanel2.setLayout(new GridLayout(0,5));
            mainPanel2.setBorder(new TitledBorder("mainPanel2"));
     
            Font largeFont = new Font("TimesRoman", Font.BOLD, 20);
            Border lineBorder = new LineBorder(Color.BLACK,2);
     
            setLayout(new BorderLayout(0,5));
     
            add(mainPanel1, BorderLayout.NORTH);
            add(mainPanel2, BorderLayout.SOUTH);
     
     
        }
     
        public static void main(String args[])
        {
            JFrame resFrame = new JFrame("Resistor Lookup");
            resFrame.setSize(500, 500);
            resFrame.setLocationRelativeTo(null);
            resFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            resFrame.setVisible(true);
        }
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Trouble getting my frame and panels to show up!?!?

    You want 'resFrame' to be resistortests object:

    resistortests resFrame = new resistortests();

    Then set the name of the frame in the resistortests() constructor. You should also respect Java naming conventions and name your classes with Capital letters, appropriately camel-cased after that, so maybe "ResistorTests."

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Trouble getting my frame and panels to show up!?!?

    Nevermind I figured it out. I didn't create a instance of my object resistortests() in main.

    Also I did a set layout to grid which didn't shrink the panels down in the North and South portions of the frame. Looking much nicer now.

    --- Update ---

    GregBrannon,

    thanks for the reply

Similar Threads

  1. Help w/ hw , help with panels layouts in frame.
    By Lenjaku in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 30th, 2013, 03:12 PM
  2. Replies: 0
    Last Post: February 15th, 2013, 05:24 PM
  3. New frame should only show GUI once!
    By gerre in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 30th, 2012, 10:34 PM
  4. Replies: 3
    Last Post: May 5th, 2012, 08:33 AM
  5. [SOLVED] .show is called in card layout, but the frame didn't update
    By nggdowt in forum AWT / Java Swing
    Replies: 2
    Last Post: November 9th, 2011, 02:16 AM