By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

GUI problem

P: 94
Sorry for yet another thread on this project :(


Here is my problem, i have done my entire project on my pc, however when i present the project I will be doing so on my laptop (which has a smaller resolution) and as such my JFrame does not fully appear on the screen. I cannot make it smaller, so i need to add a scrollbar (i think) but I am not sure how to go about doing so due to the nature in the way i set up my GUI with radiobuttons.

Please any suggestions on where I should add certain lines of code is appreciated as I have struggled with the GUI portion of this project for far too long.


This is the code that adds all of my radio buttons to the box container
Expand|Select|Wrap|Line Numbers
  1.         //Create Container for Questions
  2.             Box box1 = Box.createVerticalBox();
  3.  
  4.             //Question 1
  5.             box1.add(label1);
  6.             box1.add(rb1);
  7.             box1.add(rb2);
  8.             box1.add(rb3);
  9.             box1.add(rb4);
  10.             box1.add(Box.createVerticalStrut(5)); //spacer
  11.  
  12.             //Question 2
  13.             box1.add(label2);
  14.             box1.add(rb5);
  15.             box1.add(rb6);
  16.             box1.add(rb7);
  17.             box1.add(rb8);
  18.             box1.add(Box.createVerticalStrut(5)); //spacer
  19.  
  20.             //Question 3
  21.             box1.add(label3);
  22.             box1.add(rb9);
  23.             box1.add(rb10);
  24.             box1.add(rb11);
  25.             box1.add(rb12);
  26.             box1.add(Box.createVerticalStrut(5)); //spacer
  27.  
  28.             //Question 4
  29.             box1.add(label4);
  30.             box1.add(rb13);
  31.             box1.add(rb14);
  32.             box1.add(rb15);
  33.             box1.add(rb16);
  34.             box1.add(Box.createVerticalStrut(5)); //spacer
  35.  
  36.             //Question 5
  37.             box1.add(label5);
  38.             box1.add(rb17);
  39.             box1.add(rb18);
  40.             box1.add(rb19);
  41.             box1.add(rb20);
  42.             box1.add(Box.createVerticalStrut(5)); //spacer
  43.  
  44.             //Question 6
  45.             box1.add(label6);
  46.             box1.add(rb21);
  47.             box1.add(rb22);
  48.             box1.add(rb23);
  49.             box1.add(rb24);
  50.             box1.add(Box.createVerticalStrut(5)); //spacer
  51.  
  52.             //Question 7
  53.             box1.add(label7);
  54.             box1.add(rb25);
  55.             box1.add(rb26);
  56.             box1.add(rb27);
  57.             box1.add(rb28);
  58.             box1.add(Box.createVerticalStrut(5)); //spacer
  59.             box1.add(CloseButton);
  60.  
  61.             //Set border to make panel look nice
  62.             box1.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
  63.  
  64.             return box1;
  65.  

This is the code that creates the gui

Expand|Select|Wrap|Line Numbers
  1.         private static void createAndShowGUI() {
  2.             //Use the Java look and feel.
  3.             try {
  4.                 UIManager.setLookAndFeel(
  5.                     UIManager.getCrossPlatformLookAndFeelClassName());
  6.             } catch (Exception e) { }
  7.  
  8.             //Make sure we have nice window decorations.
  9.             JFrame.setDefaultLookAndFeelDecorated(true);
  10.  
  11.             JDialog.setDefaultLookAndFeelDecorated(true);
  12.  
  13.             //Instantiate the controlling class.
  14.             JFrame frame = new JFrame("Questionaire");
  15.  
  16.             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17.  
  18.             //Create and set up the content pane.
  19.             gui_and_Main gui = new gui_and_Main();
  20.  
  21.             //Add components to it.
  22.             Container contentPane = frame.getContentPane();
  23.  
  24.             contentPane.add(gui.createOptionControls(),BorderLayout.CENTER);
  25.             frame.getRootPane().setDefaultButton(defaultButton);
  26.  
  27.             //Display the window.
  28.             frame.pack();
  29.             frame.setLocationRelativeTo(null); //center it
  30.  
  31.             frame.setVisible(true);
  32.         }
  33.  

I tried adding a scrollpane to the project and it created a scrollbar, but the scrollbar didnt do anything. Please for the love of god somebody help me out on this.
Nov 6 '07 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
Expand|Select|Wrap|Line Numbers
  1. frame.setSize(500, 500);
?
Nov 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.