Results 1 to 7 of 7
Thread: Japplet setSize()
- 12-19-2011, 11:19 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 15
- Rep Power
- 0
Japplet setSize()
I am trying to set the size of my JApplet and whenever i use the method setSize(); nothing happens.
I do NOT get any errors and am wondering if there is a different method for this or not.
any help is appreciated.
Heres the Program:
Java Code:package ContactApp; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.JApplet; import javax.swing.JButton; public class paintJApplet extends JApplet { Color white = Color.WHITE; Color grey = Color.gray; Color c = Color.white; JButton pen = new JButton("Pencil"); JButton era = new JButton("Erase"); JButton plus = new JButton("+"); JButton minus = new JButton("-"); JButton color = new JButton("Color"); public void init() { Container frame = getContentPane(); frame.setLayout(new FlowLayout()); frame.setBackground(Color.RED); frame.setSize(200,100); frame.add(pen); frame.setVisible(true); } public void paintComponent(Graphics g) { } }
-
Re: Japplet setSize()
I am not an applet expert, but I believe that the applet's size is set from the HTML code that calls the applet.
- 12-19-2011, 11:30 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 15
- Rep Power
- 0
Re: Japplet setSize()
I know in the java.applet. there is a method (which is setSize) used to set the size of the applet. I also know that the Applet size can be changed from the html code. But i want my program to open to the proper size every time i run it. Also, the buttons added are not in the proper position when the applet is not sized properly.
-
Re: Japplet setSize()
Yes, JApplet has this method, inherited from Component, but how do you know that it actually works, that it sets the size of the applet? The applet itself isn't the top level window, but rather a component held by a top-level window created by the browser, and so I believe that it's the browser that must set the applet's size, not the java code.
One possible solution is to have your Java application call javascript code so that it could possibly talk to the browser, but I've never done this. As for improving components size and placement, a lot of this will depend on the layouts that your GUI uses. If you use flexible layout managers, you'll have an easier time with displaying your GUI in different sizes.I also know that the Applet size can be changed from the html code. But i want my program to open to the proper size every time i run it. Also, the buttons added are not in the proper position when the applet is not sized properly.
- 12-20-2011, 12:58 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: Japplet setSize()
So, given Fubarable's point that the HTML code determines the size, isn't the conclusion that your HTML code should ensure the "proper size"?I also know that the Applet size can be changed from the html code. But i want my program to open to the proper size every time i run it.
Javascript would only seem to be called for if the application decides it wants to change the size of the window within which it is appearing. If there is, in advance, a well defined "proper size", then that's what WIDTH=/HEIGHT= are for.
- 12-22-2011, 12:17 AM #6
Member
- Join Date
- Dec 2011
- Posts
- 15
- Rep Power
- 0
Re: Japplet setSize()
Dontworry i figured it out myself. You need to do:
Java Code:frame name.getContentPane().setSize(width,height);
- 12-22-2011, 01:32 AM #7
Similar Threads
-
setSize without frames
By Javaer in forum New To JavaReplies: 1Last Post: 01-09-2011, 02:41 AM -
setSize on BoxLayout
By smray7 in forum New To JavaReplies: 7Last Post: 12-15-2010, 11:18 PM -
setSize() not working?
By AedonetLIRA in forum Java AppletsReplies: 3Last Post: 12-02-2010, 05:17 AM -
When to use setSize()
By Lil_Aziz1 in forum New To JavaReplies: 7Last Post: 05-29-2010, 03:26 PM -
JFrame to JApplet or JApplet to JApplet
By ramesh.8189 in forum AWT / SwingReplies: 13Last Post: 02-08-2009, 06:14 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks