-1

Ok, like with everything I find it easier to learn when jumping into the deep end (Java, PHP, Air Traffic Controlling) I just try not to kill anybody in the process; however, I cannot find any information of how to specifically position a slider (JSlider)... I want to add it to my JPanel and at the stage I am at, setBounds would be the most logical but it doesn't like it!

I have set up the slider as follows

sensitivitySlider = new JSlider (sensitivitySlider.HORIZONTAL, 1, 1000, 500);

and initiated the variable at the beginning of the program, no problems compiling and too much of a brief (easy to most) question to find a definitive answer from googling.

Sorry if this is a little bit dumb

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Phil
  • 1,393
  • 5
  • 23
  • 42
  • 2
    Do you mean you want to know how to position your JSlider component within the JPanel so that it's near the top/bottom/left/right or such? Have you seen the [Using Layout Managers tutorial](http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html) which will explain the many options? – Bobulous May 11 '13 at 20:22
  • @Arkanon I am using this by doing mainPanel.add (sensitivitySlider); but it just doesn't appear anywhere let alone in the mainPanel – Phil May 11 '13 at 21:32
  • @Arkanon By the lack of responce I am assuming this is a pretty terrible question but we all have to start somewhere heh – Phil May 11 '13 at 21:32
  • 1
    A JPanel is not a top-level component. What is your top-level component (such as JFrame) and have you added your JPanel to that and then made the top-level component visible? – Bobulous May 11 '13 at 23:00
  • yes I am using a JFrame as top-level, I created a new JPanel and all is now going smoothley and fully visible and positionable using setBounds, thank you for your help, and for making me use my head a little more – Phil May 12 '13 at 00:15
  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) See the [Nested Layout Example](http://stackoverflow.com/a/5630271/418556) for ideas about how to *combine* layouts to create the required layout. 3) Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. For a robust GUI, instead use layout managers, or combinations of them, along with layout padding & borders for white space, to organize the components. – Andrew Thompson May 12 '13 at 05:21

1 Answers1

0

Essentially the problem was that I was not placing it on a panel, I was trying to position it directly on the main frame however I was calling for it to be placed on the mainPanel which didnt exist. Sorry for wasting server space without properly checking for the errors myself...

Phil
  • 1,393
  • 5
  • 23
  • 42