8 Replies - 3480 Views - Last Post: 11 April 2011 - 10:16 AM Rate Topic: -----

#1 Tarsus  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 06-September 10

JScrollPane add buttons vertically

Posted 11 April 2011 - 07:34 AM

Hi,

I have developed some code that creates radio buttons and adds them to a JScrollPane.. however, each radio button is added to the east (right) of the one that recedes it.

I have tried using Component

Component.BOTTOM_ALIGNMENT


which does not seems to work. Also, aligning the next button the north or south also does not work due to there being more than two buttons.

As the screenshot shows my buttons are being added horizontally.. I want them added vertically.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: JScrollPane add buttons vertically

#2 sakshamkum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 19
  • View blog
  • Posts: 232
  • Joined: 09-June 09

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 07:48 AM

see you can add all your contents into a JPanel to which you may use the required layout and then add the JPanel as a whole with the JScrollPane

This post has been edited by sakshamkum: 11 April 2011 - 07:51 AM

Was This Post Helpful? 1
  • +
  • -

#3 Tarsus  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 06-September 10

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 08:04 AM

The important elements of my code are below:-

JPanel resultsPanel = new JPanel();
JScrollPane scrollpane = new JScrollPane(resultsPanel);

resultsFrame.add(scrollpane, BorderLayout.NORTH);



resultsFrame is the main JFrame.

Later, in a for loop, I add the radio buttons, by using the following:-

 resultsPanel.add(resRadButt); 


How would I specify that content of the resultsPanel should be added to the bottom of the last, rather than to the right of the last?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 08:10 AM

You could create a Box using the Box.createVerticalBox() method.
Was This Post Helpful? 0
  • +
  • -

#5 Tarsus  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 06-September 10

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 08:35 AM

The Box worked well. It also works with a grid layout.

The side-effect, however, is that I cannot set the size of the box? It seems to grow depending on how many radio buttons are added (so rendering the scrollbar redundant).

I would like the Vertical size to be set, not dynamic as it appears to be.

both...

scrollpane.setSize(100,100);


resultsPanel.setSize(100,100);


seem to have no effect on the size of the area.
Was This Post Helpful? 0
  • +
  • -

#6 sakshamkum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 19
  • View blog
  • Posts: 232
  • Joined: 09-June 09

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 09:00 AM

can use BorderLayout.SOUTH
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 09:00 AM

Perhaps createVerticalStrut() might be more of what you are looking for, since you can control the height. Take a look at the docs for specifics of what Box has to offer.
Was This Post Helpful? 0
  • +
  • -

#8 Tarsus  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 06-September 10

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 10:02 AM

I have managed to get it working...

I have set the size of the Box using

scrollpane.setMaximumSize(new Dimension(100,100));


this was what I was looking for.

Thanks you all for the help.

This post has been edited by Tarsus: 11 April 2011 - 10:30 AM

Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: JScrollPane add buttons vertically

Posted 11 April 2011 - 10:16 AM

Then create a rigidArea. Seriously, take a look at the Documentation, which I linked to twice.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1