Results 1 to 6 of 6
Thread: Swing -> Applet size problem
- 03-07-2012, 02:34 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Swing -> Applet size problem
My problem is:
i am setting my JApplet's size to : WIDTH=400 and HEIGHT=300
on applet tag in html page.
when i execute my code on internet explorer 8, the sizes are:
java.awt.Dimension[width=380,height=285]
java.awt.Dimension[width=140,height=140]
but in mozilla 10.0.2 the sizes are:
java.awt.Dimension[width=400,height=300]
java.awt.Dimension[width=140,height=140]
this is my code:
how can i fix this ?Java Code:public class MainClass extends JApplet implements Runnable { JPanel MainPanel = new JPanel(); public void init() { MainPanel.setLayout(null); MainPanel.setOpaque(true); MainPanel.setBackground(Color.BLACK); JLabel xLabel = new JLabel("Hi"); MainPanel.add(xLabel); xLabel.setBounds(0, 0, 140, 140); //xLabel.setPreferredSize(new Dimension(140, 140)); xLabel.setOpaque(true); xLabel.setBackground(Color.WHITE); this.add(MainPanel); Dimension a = getSize(); System.out.println(a.toString()); Dimension b = xLabel.getSize(); System.out.println(b.toString()); } public void run() { } };
or how could i size my JLabel object?
(as you can see, there is a wrong about applet and JLabel sizes.)
Note : i must use setLayout nulled.
thanks.
- 03-07-2012, 06:33 PM #2
Re: Swing -> Applet size problem
First off, learn how to format code and name variables for readability: Code Conventions for the Java Programming Language: Contents
Next, learn to use layout managers and stop relying on absolute positioning: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-07-2012, 06:39 PM #3
- 03-07-2012, 07:33 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: Swing -> Applet size problem
* First off, learn how to format code and name variables for readability:
-> yes java programmers USUALLY using camel variable names, but i don't wanna use. I'm not a newbe,
so don't say to me: "learn how to format code". If there is a forum rule;
So sorry for this format.
* Next, learn to use layout managers and stop relying on absolute positioning:
-> if you are making a tank game, a table game or a card game, Which layout could be use?
Note : you can use layout managers, but view of game can be very bad, and i don't wanna program a bad game (for view).
if you will say to me "use layout manager" again and again; You can solve my problem FROM A WAY. And you know (i think), there can be a lot of possible ways on programming ?
i am making an applet "game".. so i "must" use setLayout null, i think.
Thanks for reply anyway.
- 03-07-2012, 07:53 PM #5
Re: Swing -> Applet size problem
Programmers stick to the Java naming standard the same reason writers don't write in all caps. Sure, you could go against the grain, but it's only going to make it harder for other people to read your code, and it's going to be harder for you to understand, debug, and maintain your code on your own. Getting an attitude about it is pretty pointless.
Programming a game does not automatically mean you have to use a null layout. In fact, it almost NEVER makes sense to use a null layout. If you're having a problem with the relative size of your components, aka the layout, then I'm not sure why you're scoffing at the suggestion to research layout managers.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-07-2012, 08:33 PM #6
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: Swing -> Applet size problem
my images have sizes and they are not standard (photoshop images). I don't wanna resize with image resize methods.
i don't wanna make a sizeable applet (i mean, i want to use a standard size of main applet)
anyway, thanks for your replies...
i understood, you can't help me.
thanks.
Similar Threads
-
Swing applet problem
By link6790 in forum New To JavaReplies: 9Last Post: 05-24-2011, 02:31 PM -
Java applet size problem
By madnaelo in forum Java AppletsReplies: 1Last Post: 12-06-2010, 01:39 AM -
Applet JTextField Size Problem
By a13w in forum New To JavaReplies: 4Last Post: 09-19-2009, 07:52 AM -
[SOLVED] swing dialogbox size
By MK12 in forum New To JavaReplies: 26Last Post: 02-13-2009, 05:08 PM -
setting applet's size
By nikita in forum Java AppletsReplies: 9Last Post: 10-01-2008, 04:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks