Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding ScrollPane to JFrame

Nageswar Kakolla
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Here is brief explanation about my project,

I have Frame to which I have 1 left JPanel and another Right JPanel.

in Left Panel, I have tree navigator when particular node selects, that JPanel will be loaded dynamically in Rigth Panel.

In one such Right Panel, I have array of Radio Buttons, where I want to add JScrollPane to right Panel(Ex. Site Panel) when Radio Buttons exceed display size in right Panel.

Problem is I have all code login in Site Right Panel to add Radio Buttons

and in order to right panel to JScrollpane and then add JScrollpane to JFrame is ?

i have done some example which will does same what I wanted but i am not able to do in my project since My right panel is added to JFrame some where else ?

Ne ides will be good ?

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
// new TestFrame().setVisible(true);

public static void createAndShowGUI(){
//Make sure we have nice window decorations.
JFrame m_Frame = new JFrame("RAPID");
JPanel panel = new JPanel();
// panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.setLayout(new GridBagLayout());
JRadioButton nodButton = new JRadioButton("NOD");
JRadioButton odButton = new JRadioButton("OD");
JRadioButton naButton = new JRadioButton("NA");
JRadioButton buttonList[] = new JRadioButton[30];
// Constriants for Radio Buttons
GridBagConstraints nodButtonConstraints = new GridBagConstraints();
nodButtonConstraints.fill = GridBagConstraints.NONE;
nodButtonConstraints.anchor = GridBagConstraints.CENTER;
nodButtonConstraints.weightx = 1;
nodButtonConstraints.weighty = 1;
nodButtonConstraints.gridx = 1;
nodButtonConstraints.gridy = GridBagConstraints.RELATIVE;
nodButtonConstraints.gridwidth = 1;
nodButtonConstraints.gridheight = 1;
// GridBag Layout Constraints for OD buttons
GridBagConstraints odButtonConstraints = new GridBagConstraints();
odButtonConstraints.fill = GridBagConstraints.NONE;
odButtonConstraints.anchor = GridBagConstraints.CENTER;
odButtonConstraints.weightx = 1;
odButtonConstraints.weighty = GridBagConstraints.RELATIVE;
odButtonConstraints.gridx =2;
odButtonConstraints.gridy = GridBagConstraints.RELATIVE;
odButtonConstraints.gridwidth = 1;
odButtonConstraints.gridheight = 1;

GridBagConstraints naButtonConstraints = new GridBagConstraints();
naButtonConstraints.fill = GridBagConstraints.NONE;
naButtonConstraints.anchor = GridBagConstraints.CENTER;
naButtonConstraints.weightx = 1;
naButtonConstraints.weighty = 1;
naButtonConstraints.gridx =3;
naButtonConstraints.gridy = GridBagConstraints.RELATIVE;
naButtonConstraints.gridwidth = 1;
naButtonConstraints.gridheight = 1;
String[] arrayStr = new String[] {"NOD","OD","NA","NOD","OD","NA","NOD","OD","NA","NOD","OD","NA","NOD","OD","NA","NOD","OD","NA","NOD","OD","NA","NOD","OD","NA","NOD","OD","NA","NOD","OD","NA"};
for(int i = 0; i < 30; i++) {
// panel.add(nodButton,nodButtonConstraints);
buttonList[i] = new JRadioButton(arrayStr[i]);
//panel.add(new JButton("Button " + i));

m_Frame.add(new JScrollPane(panel));

//Create and set up the window.


  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic