Re: Changing Jpanel Sizes
Generally, if you want a layout to respect a particular component's size, you should set the component preferred size (e.g. panel.setPreferredSize(..)).
Assuming the major ticks are minutes, making the slider display 60 minor ticks between minute labels means you'll have to provide your own labels. The slider only understands a single level of units, so its max value in this case will be 3 x 60 = 180 seconds. If you want major ticks every minute you must set the major tick spacing to 60. To display minute labels every major tick, you need to provide your own Dictionary of labels, set to display every 60 units. So the slider is set up something like this:
Code:
final int TOTAL_MINS = 3;
// create slider with seconds units
JSlider progressSlider = new JSlider(SwingConstants.HORIZONTAL, 0, TOTAL_MINS * 60, 0);
// create label dictionary for minute labels (put one more than the total number of mins so we get the last label)
Dictionary<Integer, Component> labels = new Hashtable<Integer, Component>(TOTAL_MINS + 1);
for (int i=0; i < TOTAL_MINS + 1; i++) {
labels.put(i*60, new JLabel(String.valueOf(i)));
}
progressSlider.setLabelTable(labels);
progressSlider.setMajorTickSpacing(60); // every minute
progressSlider.setMinorTickSpacing(1); // every 1 second
If the seconds divisions are too fine, try setting the minor tick spacing to 5 or 10, so you get a minor tick every 5 or 10 seconds.
One of the principal objects of theoretical research in any department of knowledge is to find the point of view from which the subject appears in its greatest simplicity...
J. W. Gibbs
Re: Changing Jpanel Sizes
Hi,
Thank you. It works :)