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
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.
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