Results 1 to 3 of 3
- 04-12-2011, 09:36 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 22
- Rep Power
- 0
JScrollBar... how to set the position of the scrollbar?
hi, i modified the JFreeChart code to scroll the x axis to the end by default (one of the examples has a JScrollBar incorporated).
but i cant set the position of the horizontal JScrollBar itself. scrollBar.setPosition(300,0); does not work.
how do i change the position of the scroll bar?Last edited by theChameleon; 04-12-2011 at 09:38 AM.
- 04-12-2011, 09:51 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show you code? And from where you found setPosition() on JScrollBar?
- 04-12-2011, 09:17 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 22
- Rep Power
- 0
hello, below is the source code.
it is setLocation(), not setPosition(). my mistake. ah, i found out that setLocation() doesnt move the scroll thing, but moves the whole thing instead.
so, how do i make the scrollbar start by scrolling to the right instead of the default left?
Java Code:import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.DateTickMarkPosition; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYBarRenderer; import org.jfree.data.time.*; import org.jfree.data.xy.XYDataset; import javax.swing.*; import java.awt.*; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; public class BarChartScrollBar1Demo extends JFrame { public BarChartScrollBar1Demo() { super("BarChartScrollBarlDemo"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Volume"); XYBarRenderer renderer = new XYBarRenderer(0.1); XYDataset dataset = getDataset(); Day d1 = new Day(); Day d2 = (Day) d1.next(); domainAxis.setAutoRange(false); domainAxis.setRange(new DateRange(d1.getFirstMillisecond(), d2.getFirstMillisecond())); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); mainPlot.setDomainGridlinesVisible(true); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); JFreeChart chart = new JFreeChart(null, null, mainPlot, true); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 600)); this.add(chartPanel); JScrollBar scrollBar = getScrollBar(domainAxis); this.add(scrollBar, BorderLayout.SOUTH); this.pack(); final double r1 = domainAxis.getLowerBound(); final double r2 = domainAxis.getUpperBound(); final double millisInHour = 60 * 60 * 1000; final double lowerBound = (300 * millisInHour) + r1; final double upperBound = (300 * millisInHour) + r2; [U]domainAxis.setRange(lowerBound, upperBound); // set default position, need to start the scroll bar at the right instead of the left[/U] } private XYDataset getDataset() { Hour h = new Hour(); TimeSeries s1 = new TimeSeries("Series 1", Hour.class); for (int i = 0; i < 300; i++) { h = (Hour) h.next(); s1.add(h, Math.random() * 200); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); return dataset; } private JScrollBar getScrollBar(final DateAxis domainAxis) { final double r1 = domainAxis.getLowerBound(); final double r2 = domainAxis.getUpperBound(); JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 100, 0, 400); scrollBar.addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { double x = e.getValue() * 60 * 60 * 1000; domainAxis.setRange(r1 + x, r2 + x); } }); return scrollBar; } public static void main(String[] args) { new BarChartScrollBar1Demo().setVisible(true); } }Last edited by theChameleon; 04-12-2011 at 09:27 PM.
Similar Threads
-
paint with JScrollBar
By shakeel in forum Java 2DReplies: 5Last Post: 12-23-2010, 04:35 PM -
Problem with JScrollBar
By Arthur in forum AWT / SwingReplies: 3Last Post: 02-19-2010, 02:59 AM -
JScrollBar
By solomon_13000 in forum AWT / SwingReplies: 1Last Post: 07-01-2009, 07:46 AM -
get position in string from caret position
By helloworld111 in forum AWT / SwingReplies: 5Last Post: 02-19-2009, 01:36 AM -
How to maintain scrollbar position on postback?
By marathaWarrior in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01-02-2009, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks