File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Radio Buttons with JScroll Pane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Radio Buttons with JScroll Pane" Watch "Radio Buttons with JScroll Pane" New topic
Author

Radio Buttons with JScroll Pane

An Sush
Ranch Hand

Joined: Jan 17, 2007
Posts: 47
Hi,
I am new to Swing and want to write a simple panel using swing. The requiremnets are as follows:
1) will have 3 radio buttons
2) just below that have a scroll panel and based on which radio button is selected, show different text in the scroll panel.
Kindly help me with the code or guide me to some tutorial
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

You can add an action listener to the JRadioButtons. On getting notified of the action event, you can figure out which was selected and display the text accordingly.

To display the text, you need to have a JTextComponent (something like JTextField or JTextArea) wrapped inside the JScrollPane. The scroll pane in itself is of no use for you to display text.

In a nutshell you need to:
1) Create JRadioButton instances
2) Add an action listener while creating them.
3) Create some JTextComponent instance
4) Create a container for these components(typically some panel)
5) Add all the child components to the panel using your favorite layout manager
6) Put the panel in a JFrame and display it.
7) In the action listener, figure out which button was clicked and display the text accordingly.

For a comprehensive Swing tutorial check out http://java.sun.com/docs/books/tutorial/uiswing/


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
An Sush
Ranch Hand

Joined: Jan 17, 2007
Posts: 47
oh yes i created action item, radio buttons and jscroll panel also. but m unable to set the layout for them
at parent level i have a JPanel (BorderLayout):

and i created new radio buttons:

and then added them to the JPanel:

similarly i added all the radio buttons and the scroll panel also
but on running the prog, i see only one radio button
in short m unable to set the layout/coordinates for the elements.
kindly help me with it
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

You really need to go through http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html before attempting anything further.
 
wood burning stoves
 
subject: Radio Buttons with JScroll Pane