0

Why is my JPanel spreading all over the remaining part of frame when i try to resize to whatever size i want it to occupy. . .

This is the code snippet

public class GUITabbedPane extends JFrame{

TabsPanelClasses tabPanel = new TabsPanelClasses();
public GUITabbedPane()
{
    TabsPanelClasses.CreateAccount createAccount = tabPanel.new  CreateAccount();
    TabsPanelClasses.BorrowBook borrowBook = tabPanel.new  BorrowBook();

    JTabbedPane tabs = new JTabbedPane(JTabbedPane.LEFT);

    //Tab text support html tags
    tabs.addTab("<html><body marginwidth=30 marginheight=20>Create Account</body></html>", null,createAccount.createAccountPanel(),"New Member Account");
    tabs.addTab("<html><body marginwidth=30 marginheight=20>Borrow Book</body></html>", null,borrowBook.borrowBookInputs(),"Borrowing a book");
    tabs.addTab("<html><body marginwidth=30 marginheight=20>Return Book</body></html>", null,null,"Returning a book");
    tabs.addTab("<html><body marginwidth=30 marginheight=20>Add Book</body></html>", null,null,"Adding a book record");
    tabs.addTab("<html><body marginwidth=30 marginheight=20>Delete Book</body></html>", null,null,"Deleting a book record");
    tabs.addTab("<html><body marginwidth=30 marginheight=20>Display Details</body></html>", null,null,"Books and Members details");

    add(tabs);
    pack();

}
public static void main(String[] args) {
    GUITabbedPane frame = new GUITabbedPane();

    frame.setDefaultLookAndFeelDecorated(true);
    frame.setSize(800, 400);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

}

createAccount() which returns the panel i am display in my frame. . .

     public class TabsPanelClasses {

 class CreateAccount
   {

       JLabel label = new JLabel("Applicants` name : ");
       JTextField textField = new JTextField("New members` name here");
       JLabel label1 = new JLabel("Subscription fee ");

       JRadioButton radioButton1 = new JRadioButton("$25");
       JRadioButton radioButton2 = new JRadioButton("$15");
       ButtonGroup group = new ButtonGroup();
       JButton btn = new JButton("Create Account");

       public JPanel createAccountPanel()
       {
           JPanel panel = new JPanel(new GridLayout(3,2));

           panel.setBorder(new TitledBorder("Create Account"));
           panel.add(label);
           panel.add(textField);


           panel.add(label1);
           group.add(radioButton1);
           group.add(radioButton2);

           panel.add(radioButton1);
           panel.add(radioButton2);
           panel.add(btn);
           panel.setVisible(false);
           panel.setSize(new Dimension(50,50));
           panel.revalidate();
           panel.repaint();

           return panel;

       }



   }


}
7
  • For better help sooner, post an SSCCE. Oct 20, 2013 at 9:47
  • mu question is precise Oct 20, 2013 at 10:04
  • Good for you! My answer is waiting on an SSCCE. Oct 20, 2013 at 10:05
  • yes, now my post is SSCCE! Oct 20, 2013 at 10:24
  • An SSCCE can have only one public class. Which code do you (mistakenly) think is the SSCCE? Oct 20, 2013 at 10:27

1 Answer 1

0

Set the layout of your frame aswell:

frame.setLayout(LayoutManager);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.