Results 1 to 6 of 6
- 05-09-2010, 09:27 PM #1
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
How to center a window with Container [SOLVED] [Thanks!]
Hi I'm using a container class only object. Not using JFrame window which is centered with frame.setLocationRelativeTo(null); sentence.
I just want the splash screen of my application appears in the center of the desktop not in the upper-left part.
Any solution? I'm new with Java :D thanks in advance
This is the code
public class MenuSwing3 extends JFrame {
Container contenedor;
JTextArea areaTexto;
JMenuBar barraMenu = new JMenuBar();
JMenu menuFirmar = new JMenu("Firmar");
JMenu menuValidar = new JMenu("Validar");
JMenu menuAyuda = new JMenu("Ayuda");
JMenuItem opcionEnvelope = new JMenuItem("Documento XML en formato Envelope");
JMenuItem opcionEnveloping = new JMenuItem("Documento XML en formato Enveloping");
JMenuItem opcionDetached = new JMenuItem("Documento anexo - formato Detached");
JMenuItem opcionSalirF = new JMenuItem("Salir");
//Constructor de la clase MenuSwing3
public MenuSwing3() {
super("Firma digital de documentos");
contenedor = getContentPane();
menuFirmar.add(opcionEnvelope);
menuFirmar.add(opcionEnveloping);
menuFirmar.add(opcionDetached);
menuFirmar.add(opcionSalirF);
barraMenu.add(menuFirmar);
barraMenu.add(menuValidar);
barraMenu.add(menuAyuda);
setJMenuBar(barraMenu);
addWindowListener(new WindowHandler());
opcionEnvelope.addActionListener(new VigilaMenu());
opcionEnveloping.addActionListener(new VigilaMenu());
opcionDetached.addActionListener(new VigilaMenu());
opcionSalirF.addActionListener(new VigilaMenu());
setSize(512,384);
areaTexto = new JTextArea();
contenedor.add("Center",areaTexto);
setIconImage(Toolkit.getDefaultToolkit().createIma ge("Icono.gif"));
show();
}Last edited by fernandoj; 05-09-2010 at 10:57 PM.
- 05-09-2010, 09:56 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
I don't understand your question. You are using a JFrame. You are aware of the setLocationRelativeTo( null ) method. Basic code should be:
If you need more help post your SSCCE.Java Code:setSize(...); setLocationRelativeTo( null ); setVisible( true );
- 05-09-2010, 10:41 PM #3
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
Thank you very much. You are right and it works!
I forgot that class extended JFrame. The confusion came because Container is upper in the heritance so I thought I had to use only the methods for Container class.

By the way, what's better? the show(); method or setVisible( true );
I hope in a few weeks I can manage better with Java :p
- 05-09-2010, 10:45 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Read the API description for both methods to see whast the difference is.By the way, what's better? the show(); method or setVisible( true );
- 05-09-2010, 10:53 PM #5
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
It seems show method is deprecated! I will use setVisible :D
Java Code:setVisible public void setVisible(boolean b) Shows or hides this component depending on the value of parameter b. Parameters: b - if true, shows this component; otherwise, hides this component Since: JDK1.1 See Also: isVisible() show @Deprecated public void show() Deprecated. As of JDK version 1.1, replaced by setVisible(boolean).
- 05-09-2010, 11:00 PM #6
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Similar Threads
-
Need to pass a value from a parent window to a pop up or child window
By blackpanther in forum Advanced JavaReplies: 4Last Post: 01-10-2010, 07:48 AM -
change url in parent window from child window
By rakesh_n_mehta in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-09-2009, 12:17 PM -
how can i move one frame window to another window
By santhosh_el in forum AWT / SwingReplies: 8Last Post: 06-10-2009, 03:36 PM -
[SOLVED] Coordinates container --> in parent container.
By Cleite in forum AWT / SwingReplies: 3Last Post: 04-21-2009, 11:01 PM -
Help Center Live 2.1.3
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-06-2007, 03:43 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks