Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Setting Title from Jpanel to Jframe
Venkatesh Raman
Greenhorn
Posts: 8
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have two Radio Buttons on a Jpanel. And this Jpanel is placed on a JFrame. Now based on the radio buttons the user clicks I need to change the title on the Jframe.
Can anybody help me on this.
Thanks
Gregg Bolinger
Ranch Hand
Posts: 15304
6
I like...
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Try this, not sure it works or not.
myJFrame.setTitle("Some Title");
myJFrame.repaint();
------------------
Happy Coding,
Gregg Bolinger
Venkatesh Raman
Greenhorn
Posts: 8
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
How do I get the Frame from the Jpanel ?
Gregg Bolinger
Ranch Hand
Posts: 15304
6
I like...
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I assume your code looks similar to this??
import java.awt.*; import javax.swing.*; class mainFrame extends JFrame { static JFrame frame; static JPanel panel; public mainFrame() { panel = new JPanel(); setContentPane(panel); panel.setLayout(null); } public static void main(String[] args) { frame = new mainFrame(); frame.setVisible(true); frame.setExtendedState(frame.MAXIMIZED_BOTH); //JDK1.4 specific } }
frame is your JFrame.
In your Radio Button Listener, just access frame like, frame.setTitle("fjdsk");
------------------
Happy Coding,
Gregg Bolinger
[This message has been edited by Gregg Bolinger (edited October 25, 2001).]
Nathan Pruett
Bartender
Posts: 4121
I like...
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You have two choices... you can either do things the "normal" way...
import java.awt.*; import java.awt.event.*; public class NameFrame extends Frame implements ItemListener { public NameFrame() { super( "Name 1" ); Panel p = new Panel(); CheckboxGroup cbg = new CheckboxGroup(); Checkbox cb1 = new Checkbox( "Name 1", cbg, true ); Checkbox cb2 = new Checkbox( "Name 2", cbg, false ); cb1.addItemListener( this ); cb2.addItemListener( this ); p.add( cb1 ); p.add( cb2 ); add( p ); addWindowListener( new ExitHandler() ); } public void itemStateChanged( ItemEvent event ) { this.setTitle( event.getItem().toString() ); } public static void main( String[] args ) { NameFrame f = new NameFrame(); f.setSize( 300, 300 ); f.setVisible( true ); } private class ExitHandler extends WindowAdapter { public void windowClosing( WindowEvent event ) { System.exit( 0 ); } } }
Or, if you have a specialized child of Panel... the "other" way...
import java.awt.*; import java.awt.event.*; public class SubPanel extends Panel implements ItemListener { public SubPanel() { CheckboxGroup cbg = new CheckboxGroup(); Checkbox cb1 = new Checkbox( "Name 1", cbg, true ); Checkbox cb2 = new Checkbox( "Name 2", cbg, false ); cb1.addItemListener( this ); cb2.addItemListener( this ); add( cb1 ); add( cb2 ); } public void itemStateChanged( ItemEvent event ) { Component c = getParent(); while( c.getParent() != null ) { c = c.getParent(); } Frame topFrame = ( Frame )c; topFrame.setTitle( event.getItem().toString() ); } }
import java.awt.*; import java.awt.event.*; public class NameFrame extends Frame { public NameFrame() { super( "Name 1" ); SubPanel p = new SubPanel(); add( p ); addWindowListener( new ExitHandler() ); } public static void main( String[] args ) { NameFrame f = new NameFrame(); f.setSize( 300, 300 ); f.setVisible( true ); } private class ExitHandler extends WindowAdapter { public void windowClosing( WindowEvent event ) { System.exit( 0 ); } } }
-Nate
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Venkatesh Raman
Greenhorn
Posts: 8
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot guys !!! It works perfectly !!! It is really great to post on this site..
Paul Stevens
Ranch Hand
Posts: 2823
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Even better to get the answers
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Multiple controls in a panel
Alignment of RadioButtons
Radio Buttons with JScroll Pane
slow loading of JPanel
Adding ScrollPane to JPanel
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...