Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set size of jframe form

Status
Not open for further replies.

OhioSteve

MIS
Mar 12, 2002
1,352
US
I have an extremely simple question. I have created my first jframe form using the NetBeans IDE. When I run the form, it displays at the top of my monitor. It is only about one inch high. However, I can resize to more normal dimensions.

How can I set it to be 5 inches x 7 inches all the time??

I have looked at all of the properties and I suspect that I need to change "preferredSize". However, I can't change it in the GUI. Whenever I change the numbers, they just revert to the old settings.
 
Actually, I cannot edit MANY of my form's properties. They are disabled in the GUI. In the code view, they have a light blue background. This is incredibly frustrating!!

How do I allow myself to edit everything??
 
I don't know anything about NetBeans, but you can set the size of a JFrame in code using the JFrame.setSize(Dimension) or JFrame.setSize(int width, int height) methods.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Hi OhioSteve,

U can do it by setting a property called maximisedbounds in the other properties tab of a NetBeans editor. This takes four values X,Y,Width,Height. But u should provide values in terms of pixcell not in inches.

when U click on play button in NetBeans to run your application It will start at a corner even u specify the x,y co-ordinate, but when u click on maximize button of the frame it will behave as u have specified.

Ther is a work around for this problem. It is true that u can not modify the code in the method initcomponents(blue color area) but u can edit the area where u Instantiate the Frame. There can set the frame size. I will paste some code which shows how to set frame size.



/*
* StepsTab.java
*
* Created on April 12, 2005, 4:15 PM
*/

package GUIApplications.GUIApplications;

/**
*
* @author venkatesh.r
*/
public class StepsTab extends javax.swing.JFrame {

/** Creates new form StepsTab */
public StepsTab() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();

getContentPane().setLayout(null);

setTitle("Protocol Steps");
setMaximizedBounds(new java.awt.Rectangle(250, 250, 400, 400));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});

jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"1", "Step1", "Functional"},
{"2", "Step2", "Functional"},
{"3", "Step3", "Functional"}
},
new String [] {
"S.No.", "Step Name", "Step Type"
}
));
jScrollPane1.setViewportView(jTable1);

getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(10, 10, 370, 70);

jButton1.setText("Add");
getContentPane().add(jButton1);
jButton1.setBounds(60, 200, 56, 26);

jButton2.setText("Edit");
getContentPane().add(jButton2);
jButton2.setBounds(150, 200, 55, 26);

jButton3.setText("Remove");
getContentPane().add(jButton3);
jButton3.setBounds(240, 200, 80, 26);

pack();
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
I modified the following code to set the Frame size.
U can see its effect by commenting the setSize and setLocation methods of the frame.
*/
javax.swing.JFrame frm = new StepsTab();
frm.setSize(400,400);
frm.setLocation(100,100);
frm.show();
}


// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration

}



Bye,
R.Venkatesh
Ocimum Biosolutions,
Banjarahills,Hyd


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top