Results 1 to 6 of 6
Thread: JFrame refresh problem
- 02-03-2010, 03:39 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
JFrame refresh problem
Hi
I have been coding Java for a couple of days, having come from a C background.
I have an application that displays a JFrame with a JFreeChart object held in the centre and three buttons in the south layout.
I have registered action listeners to the button, and the idea is to re draw the graph with a moving average series.
I can see my callback, but am unable to redraw the chart. What do I need to do to get the frame to redraw?
thanks
elliot
Java Code:public void graphData() { String[] chartInfo = { "Gold Price USD", "Date /(Yr/)", "Price /(USD/)" }; JButton monthBtn = new JButton("M"); JButton sixMBtn = new JButton("6M"); JButton yearBtn = new JButton("1Y"); final TimeSeriesChart tsc = new TimeSeriesChart("Gold Price (USD)", "Date (Yr)", "Price (USD)"); final int[] yIntArr = new int[ySeries.length]; for (int i = 0; i < ySeries.length; i++) { yIntArr[i] = (int) ySeries[i]; } final JFrame graphFrame = new JFrame(); BorderLayout bl = new BorderLayout(); graphFrame.setLayout(bl); graphFrame.add(tsc.createPanel(xSeries, yIntArr, "null"), BorderLayout.CENTER); JPanel southPanel = new JPanel(); monthBtn.addActionListener(new ActionListener (){ public void actionPerformed(ActionEvent e){ graphFrame.add(tsc.createPanel(xSeries, yIntArr, "month"), BorderLayout.CENTER); graphFrame.repaint(); } }); sixMBtn.addActionListener( new ActionListener (){ public void actionPerformed(ActionEvent e){ graphFrame.add(tsc.createPanel(xSeries, yIntArr, "sixmonth"), BorderLayout.CENTER); graphFrame.repaint(); } }); yearBtn.addActionListener( new ActionListener (){ public void actionPerformed(ActionEvent e){ graphFrame.add(tsc.createPanel(xSeries, yIntArr, "year"), BorderLayout.CENTER); graphFrame.repaint(); System.out.println("here......."); } }); southPanel.add(monthBtn); southPanel.add(sixMBtn); southPanel.add(yearBtn); graphFrame.add(southPanel, BorderLayout.SOUTH); graphFrame.setVisible(true); graphFrame.pack(); }
-
If you add a new component, you will need to call revalidate on the the JPanel/container and sometimes repaint (as you are already doing).
- 02-03-2010, 09:06 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
Many thanks :-)
-
- 02-03-2010, 10:36 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
Thanks... how do I show as solved? I could not edit the title.
-
Similar Threads
-
Problem-----JFrame
By HariPrasad in forum AWT / SwingReplies: 2Last Post: 07-28-2009, 12:34 PM -
GUI refresh problem in java 1.6
By gokhan in forum Java AppletsReplies: 2Last Post: 09-26-2008, 12:23 PM -
My Simple Refresh Problem
By pmcastillo in forum New To JavaReplies: 0Last Post: 03-26-2008, 07:59 AM -
JFrame problem
By vassil_zorev in forum AWT / SwingReplies: 1Last Post: 01-25-2008, 02:53 AM -
JFrame problem
By saytri in forum New To JavaReplies: 6Last Post: 01-11-2008, 05:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks