How to set the frame size?
Hi,
Can some one show me how to set the frame size in this program? History: I have created a window and added a button but its to small. So I want to increase the size of the frame to at least 600X400 pixel.
private static void showGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ButtonDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
Main newContentPane = new Main();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}It would be nice if you could show me how to do it.
Thank you very much for reading this.
Challenger wrote:
Simply adding
frame.setSize(new Dimension(600,400));to the end of your code should work perfectly.Or, if you want to do it correctly, .setPreferredSize() on your frame before you .pack() it. The default layout manager for JFrame is BorderLayout, which uses the preferredSize of each component to calculate sizes during the .pack() call.
Similar Messages
-
I am Making a program for purchasing games, with the basic layout alsot done, except on problem. When the purchase button is pressed, a dialog shows up but nothing is seen until i resize it. How would i set the frame size so that i do not need to resize it each time? below is the code for the files. Many thanks in advance.
CreditDialog
import java.awt.*;
import java.awt.event.*;
class CreditDialog extends Dialog implements ActionListener { // Begin Class
private Label creditLabel = new Label("Message space here",Label.RIGHT);
private String creditMessage;
private TextField remove = new TextField(20);
private Button okButton = new Button("OK");
public CreditDialog(Frame frameIn, String message) { // Begin Public
super(frameIn); // call the constructor of dialog
creditLabel.setText(message);
add("North",creditLabel);
add("Center",remove);
add("South",okButton);
okButton.addActionListener(this);
setLocation(150,150); // set the location of the dialog box
setVisible(true); // make the dialog box visible
} // End Public
public void actionPerformed(ActionEvent e) { // Begin actionPerformed
// dispose(); // close dialog box
} // End actionPerformed
} // End Class
MobileGame
import java.awt.*;
import java.awt.event.*;
class MobileGame extends Panel implements ActionListener { // Begin Class
The Buttons, Labels, TextFields, TextArea
and Panels will be created first.
private int noOfGames;
// private GameList list;
private Panel topPanel = new Panel();
private Panel middlePanel = new Panel();
private Panel bottomPanel = new Panel();
private Label saleLabel = new Label ("Java Games For Sale",Label.RIGHT);
private TextArea saleArea = new TextArea(7, 25);
private Button addButton = new Button("Add to Basket");
private TextField add = new TextField(3);
private Label currentLabel = new Label ("Java Games For Sale",Label.RIGHT);
private TextArea currentArea = new TextArea(3, 25);
private Button removeButton = new Button("Remove from Basket");
private TextField remove = new TextField(3);
private Button purchaseButton = new Button("Purchase");
private ObjectList gameList = new ObjectList(20);
Frame parentFrame; //needed to associate with dialog
All the above will be added to the interface
so that they are visible to the user.
public MobileGame (Frame frameIn) { // Begin Constructor
parentFrame = frameIn;
topPanel.add(saleLabel);
topPanel.add(saleArea);
topPanel.add(addButton);
topPanel.add(add);
middlePanel.add(currentLabel);
middlePanel.add(currentArea);
bottomPanel.add(removeButton);
bottomPanel.add(remove);
bottomPanel.add(purchaseButton);
this.add("North", topPanel);
this.add("Center", middlePanel);
this.add("South", bottomPanel);
addButton.addActionListener(this);
removeButton.addActionListener(this);
purchaseButton.addActionListener(this);
The following line of code below is
needed inorder for the games to be
loaded into the SaleArea
} // End Constructor
All the operations which will be performed are
going to be written below. This includes the
Add, Remove and Purchase.
public void actionPerformed (ActionEvent e) { // Begin actionPerformed
If the Add to Basket Button is pressed, a
suitable message will appear to say if the game
was successfully added or not. If not, an
ErrorDialog box will appear stateing the error.
if(e.getSource() == addButton) { // Begin Add to Basket
// GameFileHandler.readRecords(list);
try { // Begin Try
String gameEntered = add.getText();
if (gameEntered.length() == 0 ) {
new ErrorDialog (parentFrame,"Feild Blank");
} else if (Integer.parseInt(gameEntered)< 0
|| Integer.parseInt(gameEntered)>noOfGames) { // Begin Else If
new ErrorDialog (parentFrame,"Invalid Game Number");
} else { // Begin Else If
//ADD GAME
} // End Else
} catch (NumberFormatException num) { // Begin Catch
new ErrorDialog(parentFrame,"Please enter an Integer only");
} // End Catch
} // End Add to Basket
If the Remove From Basket Button is pressed, a
a suitable message will appear to say if the
removal was successful or not. If not, an
ErrorDialog box will appear stateing the error.
if(e.getSource() == removeButton) { // Begin Remove from Basket
try { // Begin Try
String gameEntered = remove.getText();
if (gameEntered.length() == 0 ) {
new ErrorDialog (parentFrame,"Feild Blank");
} else if (Integer.parseInt(gameEntered)< 1
|| Integer.parseInt(gameEntered)>noOfGames) { // Begin Else If
new ErrorDialog (parentFrame,"Invalid Game Number");
} else { // Begin Else If
//ADD GAME CODE
} // End Else
} catch (NumberFormatException num) { // Begin Catch
new ErrorDialog(parentFrame,"Please enter an Integer only");
} // End Catch
} // End Remove from Basket
If the purchase button is pressed, the
following is executed. NOTE: nothing is done
when the ok button is pressed, the window
just closes.
if(e.getSource() == purchaseButton) { // Begin Purchase
String gameEntered = currentArea.getText();
if (gameEntered.length() == 0 ) {
new ErrorDialog (parentFrame,"Nothing to Purchase");
} else { // Begin Else If
new CreditDialog(parentFrame,"Cost � 00.00. Please enter Credit Card Number");
} // End Else
} // End Purchase
} // End actionPerformed
} // End Class
RunMobileGame
import java.awt.*;
public class RunMobileGame { // Begin Class
public static void main (String[] args) { // Begin Main
EasyFrame frame = new EasyFrame();
frame.setTitle("Game Purchase for 3G Mobile Phone");
MobileGame purchase = new MobileGame(frame); //need frame for dialog
frame.setSize(500,300); // sets frame size
frame.setBackground(Color.lightGray); // sets frame colour
frame.add(purchase); // adds frame
frame.setVisible(true); // makes the frame visible
} // End Main
} // End Class
EasyFrame
import java.awt.*;
import java.awt.event.*;
public class EasyFrame extends Frame implements WindowListener {
public EasyFrame()
addWindowListener(this);
public EasyFrame(String msg)
super(msg);
addWindowListener(this);
public void windowClosing(WindowEvent e)
dispose();
public void windowDeactivated(WindowEvent e)
public void windowActivated(WindowEvent e)
public void windowDeiconified(WindowEvent e)
public void windowIconified(WindowEvent e)
public void windowClosed(WindowEvent e)
System.exit(0);
public void windowOpened(WindowEvent e)
} // end EasyFrame class
ObjectList
class ObjectList
private Object[] object ;
private int total ;
public ObjectList(int sizeIn)
object = new Object[sizeIn];
total = 0;
public boolean add(Object objectIn)
if(!isFull())
object[total] = objectIn;
total++;
return true;
else
return false;
public boolean isEmpty()
if(total==0)
return true;
else
return false;
public boolean isFull()
if(total==object.length)
return true;
else
return false;
public Object getObject(int i)
return object[i-1];
public int getTotal()
return total;
public boolean remove(int numberIn)
// check that a valid index has been supplied
if(numberIn >= 1 && numberIn <= total)
{ // overwrite object by shifting following objects along
for(int i = numberIn-1; i <= total-2; i++)
object[i] = object[i+1];
total--; // Decrement total number of objects
return true;
else // remove was unsuccessful
return false;
ErrorDialog
import java.awt.*;
import java.awt.event.*;
class ErrorDialog extends Dialog implements ActionListener {
private Label errorLabel = new Label("Message space here",Label.CENTER);
private String errorMessage;
private Button okButton = new Button("OK");
public ErrorDialog(Frame frameIn, String message) {
/* call the constructor of Dialog with the associated
frame as a parameter */
super(frameIn);
// add the components to the Dialog
errorLabel.setText(message);
add("North",errorLabel);
add("South",okButton);
// add the ActionListener
okButton.addActionListener(this);
/* set the location of the dialogue window, relative to the top
left-hand corner of the frame */
setLocation(100,100);
// use the pack method to automatically size the dialogue window
pack();
// make the dialogue visible
setVisible(true);
/* the actionPerformed method determines what happens
when the okButton is pressed */
public void actionPerformed(ActionEvent e) {
dispose(); // no other possible action!
} // end class
I Know there are alot of files. Any help will be much appreciated. Once again, Many thanks in advancesetSize (600, 200);orpack ();Kind regards,
Levi
PS:
int i;
parses to
int i;
, but
[code] int i;[code[i]]
parses to
int i; -
Hi, I am using Indesign CS6, How to set the page size in Inches.
Hi, I am using Indesign CS6, How to set the page size in Inches.
All fields in InDesign can be entered in any measurement system. So, if you want to make an 8"x10" document and go to File>New Document and the window looks like this:
…you can type either 8 in or 8" into the Width field like this:
…and when you move to the next field, it will convert the eight inches into the equivalent number in the unit of measure that it is using at the moment, like this:
… (203.2 milimeters is the same as 8 inches). You can also enter a different measurement unit into other fields once the file is created, such as the width or height of a frame, or the position of an object in the X and Y coordinates.
If you would rather just work in inches instead of having to type the inches mark or abbreviation, go to InDesign>Preferences>General and select the Units & Increments tab. There you will see Ruler Units for Horizontal and Vertical at the top of the window. Set them to Inches and all of the fields will display in inches. If you do that to an open document, you will change the unit of measure for that document. If you do it while no documents are open, it will change the unit of measure for any new documents you create. To change the unit of measure for existing documents, you will have to open each and make the change. -
How to set the fix size jframe window
when I run the jframe ,the jframe window size is very small
1)how to set the fix size jframe window??
2)how to set the jframe cannot change the window size??
thx~~1. You can set the size by calling JFrame's method setSize. There are two versions of this method: (1) setSize(int width, int height) and (2) setSize(Dimension d). Note, that when you use this method to set the frame size, you don't have to call JFrame's pack method.
2. JFrame has a method called setResizable(boolean resizable) which you can call with the argument false.
Without any ill intent, these questions are regarding something that is very easily answered by looking at the documentation for the JFrame class. I suggest to anyone working with swing to at least look briefly through the base classes they're extending before giving up. In my experience it is always more gratifying to figure things out on my own than asking someone. But please don't take this the wrong way, I respect people who seek out help in order to further their knowledge, instead of just giving up. -
How to set the screen size with nested Iview screen
Can someone show me how to set the screen size with nested IView screen.
at the moment i only try it with trial and error untill it looks somewhat close. Is there a property in VC to set the size for Height and width.
The same question is for the form. the form elements inside the form is easy but the actual form is still a challenge.Hi,
Yes you are correct ,Still the Form and iview are not able to change thier Layout Structure using a Propery.
it is available with VC7.1
Govindu -
Hi,
How to set the page size of a B tree node in berkeley db java edition?
thanks.The two systems have different performance characteristics. If you are concerned with the performance characteristics, then the best way to tell is to benchmark them.
By the way, both BDB and BDB JE are B-trees. -
How to set the Font size of Label?????
Hello everyone.
I want to knoe how to set the Font size of the Label???
Please help..
Thanks a lot.
GloriaLabel myLabel = new Label("Hello World");
//Font(String name, int style, int size)
myLabel.setFont(new Font("Arial", Font.PLAIN, 12)); -
How to set the minimum size of the JDialog.
Hi Could any one tell me ,
How to set the minimmum size of the JDailog.
I am using the JDialog's setMinimumSize(...)
But it is not working.....
Regards -
Vikas Kumar sahuThat's pretty much all there is, although you could always add a componentlistener and manually not let the size go below your minimum.
Or you could try overriding setSize... -
How to set the heap size of JVM
please let me know that how to set the heap size of JVM
C:\>java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xrunhprof[:help]|[:<option>=<value>, ...]
perform JVMPI heap, cpu, or monitor profiling
-Xdebug enable remote debugging
-Xfuture enable strictest checks, anticipating future default
-Xrs reduce use of OS signals by Java/VM (see documentation)look at the -Xm? lines
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap sizeThis can be used e.g. like this:java -Xms8M -Xmx32M MyProgwhich runs MyProg in a java VM with the initial heap size of 8 MB and a maximum heap size of 32 MB.
- Marcus -
How to set the stack size for alchemy application?
Anybody know how to set the stack size for alchemy application?
If you know, please tell me how to adjust the stack size for alchemy application?Hi,
The stack size is set as public const gstackSize in the alchemy generated code. You can see this if you build with ACHACKS_TMPS set. The default is one megabyte.
One way to change the stack size is to use llvm-dis to disassemble avm2-libc/lib/avm2-libc.l.bc, generating avm2-libc.l.ll, modify the constant, and then use llvm-as to recompile your modified library and overwrite the old one. These utilities should be in your path if alchemy is set up. -
How do you set the frame size?
Trying to set a frame size for 1920px X 1080px but can't see where to set this in a new project?
Frame dimensions are a property of the sequence, not the project. A project can contain multiple sequences with different properties.
File>New>Sequence opens a dialog where you can choose a preset or configure custom settings. Several of the preset groups have 1920x1080 options.
Asssuming you have footage of those dimensions that you'll be using in the sequence, then you can simply create a sequence from an asset. Either drag it to the New Item button in the Project panel's lower right corner, or right-click it and select New Sequence from Clip. -
How to set the cell size in a JFrame
Hello. Is there any way of setting the cell size in a JFrame. The reason why I want to set the cell size is that I want to be sure of their location that when I am placing components on the JFrame. So is there any way of setting the cell size beforehand. Also for the following code.
JFrame frame = new JFrame("Window");
frame.setSize(100,100);is the size 100 by 100 is he size of the cell?smithbrian wrote:
When I am placing a component on the grid I want to be sure the component is exactly where I place it. In order to do that I would need to know what is the size of the gird and how to change the size of the gird in the JFrame.What grid?? You're assuming that we know much more about your program than we actually do. We actually know zip. Please read this help site which will help you to avoid similar errors in posting questions here. It has helped me in the past: [smart questions|http://www.catb.org/~esr/faqs/smart-questions.html] -
How to Set the Paper Size in Smart Forms
Hi Friends,
I need to SET the Paper Size to default A4 in a smart form...and in some other case we need to set to other type 8.5 X 11...How can i set it....?Moving this discussion to the Scanning & OCR forum.
-
How to set the paper size when printing to postscript...
I need help in setting the paper size in the PrintPreference when using either the Postcript File or Adobe PDF printer to generate ps files.
Here's what I am doing (in c++) and I seem to be getting only 8.5x11 no matter the document page size:
LPDISPATCH p_Dispatch = Document.DocumentPreferences();
p_Dispatch = Document.DocumentPreferences();
if(p_Dispatch)
DocPreference docPreference(p_Dispatch);
pgOrientation = (idPrintPageOrientation)docPreference.get_PageOrientation();
pageW = docPreference.get_PageWidth();
pageH = docPreference.get_PageHeight();
paperSize = docPreference.get_PageSize();
docPreference.ReleaseDispatch();
p_Dispatch = Document.PrintPreferences();
if (p_Dispatch)
{ PrintPreference printPreference(p_Dispatch)printPreference.SetPrinter(idPostscriptFile);
printPreference.PrintFile(outfile);
printPreference.SetPaperSize(paperSize ); /*I have also tried idCustom but it crashes with invalid parameter for the object type.*/
printPreference.SetPaperWidth(pageW);
printPreference.SetPaperHeight(pageH);
VARIANT vprinterPresetType;
vprinterPresetType.vt = VT_I4;
vprinterPresetType.lVal = CInDesignApplication::idCustom;
Document.PrintOut(FALSE, vprinterPresetType);....
So how do i pas the document paper size to the print preset or preference?
I appreciate your input.Moving this discussion to the Scanning & OCR forum.
-
How to set the Range size dynamically in an Iterator?
Hi,
One of my scenrio, i read the range size of Iterator and i performed the business logic validation. But in my case, range size is changed as per business requriement for a paricular Iterator.
Is it possible to set the Range size property dynamically in an Iterator of pageDef File.
I'm using JDeveloper 11.1.1.3.0
Can anyone help me regarding this???
Thanks & Regards,
Perumal SGood afternoon,
This works: f?p=1:#MYPAGENUMBERCOLUMN#::Session:Request:Debug:Clearcache:itemname:itemvalue:printerfreindly
It works very well. I have been struggling for a couple of hours trying to figure out how to calculate the page number I wanted to link to from a report column defined as a linked item. I ended up modifying my VIEW to include the page number for that particular type of data and use this technique to jump to the correct page.
Thanks for posting this. Nothing else seems to work.
Don.
Maybe you are looking for
-
Itunes does not install or update on my computer or any other one i've tried
I have been trying to install itunes on my mums windows 7 laptop for the past two weeks, and nothing is working. I first try to update it but this did not work. so I unistalled it and then removed all temp files etc, this has not worked. I've tried t
-
Lightroom backups folder. Huge size.
In "My Pictures" is a folder called Lightroom, where all the catalogues and backups are stored. A while ago, I had a major crash on the computer and lost everything on my hard disc. I was able to restore most from my external hard drive. Now, in th
-
Anyone been getting these messages more frequently lately? Additionally, it seems as though there has been an increase in pixelation/audio drop outs in several HD channels. Currently I cannot view Sci HD as it is currently unavailable. I am in the Pi
-
MM Inbound Delivery and tcodes.
Hi gurus, I am a abaper working in MM Module and came across this post from bijay kumar: The Inbound process comprises all the steps of an external procurement process that occur when the goods are received. The process is: Purchase order --> Goods
-
Need help setting up a file sharing with VISTA
Hi, Can somebody help me with setting up a connection to a Windows Vista computer. I followed all the instructions from this forum but still it doesn't work. Here is what I'm doing: 1) Sharing -> File Sharing -> enabled 2) Sharing -> Options -> activ