Andei procurando informações sobre o método getContentPane() mas não achei nada esclarecedor sobre o assunto.
A minha pergunda é:
-Pra que serve esse método?
-Como posso utiliza-lo?
Andei procurando informações sobre o método getContentPane() mas não achei nada esclarecedor sobre o assunto.
A minha pergunda é:
-Pra que serve esse método?
-Como posso utiliza-lo?
É como se existisse uma capa sobre o frame, onde você adiciona os outros componentes (textfields, textareas, labels etc …).
Para você adicionar um componente desse nessa “capa”, você deve ter uma referência para este objeto (Container). Para você obter essa referência, você utiliza o método getContentPane().
Container c = getContentPane().
Aí você pode adicionar outros componentes nessa “capa” que fica sobre o Frame.
c.add(jLabel);
c.add(jtxtField);
…
É mais ou menos isso …
E ae…
Sem essa “capa” eu conseguiria adicionar os componentes?
nao
Ola,
A resposta a sua pergunta é não. De acordo com as especificações, o add direto no JFrame causa um erro de runtime.
Mas vc pode subistituir este ContantPane, setando um novo Container, que pode ser um JPanel por exemplo…
Na versão 5 sim.
Você simplesmente utiliza o método add.
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#swing
Swing
With the 1.4.2 release we provided two new look and feels for Swing: XP and GTK. Rather than taking a break, in 5.0 we’re providing two more look and feels: Synth, a skinnable look and feel, and Ocean, a new theme for Metal. Beyond look and feels, we’ve added printing support to JTable, which makes it trivial to get a beautiful printed copy of a JTable. Lastly, after seven years, we’ve made jFrame.add equivalent to jFrame.getContentPane().add().
http://forum.java.sun.com/thread.jspa?threadID=622465&messageID=3523917
http://www-static.cc.gatech.edu/classes/cs4812_99_winter/swing/sld014.htm
[quote=“rodolfocoutinho”]Na versão 5 sim.
Você simplesmente utiliza o método add.
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#swing
Swing
With the 1.4.2 release we provided two new look and feels for Swing: XP and GTK. Rather than taking a break, in 5.0 we’re providing two more look and feels: Synth, a skinnable look and feel, and Ocean, a new theme for Metal. Beyond look and feels, we’ve added printing support to JTable, which makes it trivial to get a beautiful printed copy of a JTable. Lastly, after seven years, we’ve made jFrame.add equivalent to jFrame.getContentPane().add().
http://forum.java.sun.com/thread.jspa?threadID=622465&messageID=3523917
http://www-static.cc.gatech.edu/classes/cs4812_99_winter/swing/sld014.htm[/quote]
Interessante… desta eu não sabia… 8O
Opa…
we’ve made jFrame.add equivalent to jFrame.getContentPane().add().
entao… ???