java - Next and Previous Buttons Displaying Charts Malfunction -
i trying step through arraylist<jpanel> contains chartpanels. next button correctly steps through charts expected, when click previous button nothing happens. feel logic may convoluted. thanks!
note: panelcombination jpanel.
code buttons:
public static int advance = 0; public static arraylist<jpanel> chartlist = new arraylist<>(); private void nextmouseclicked(java.awt.event.mouseevent evt) { panelcombination.removeall(); panelcombination.add(chartlist.get(advance)); panelcombination.validate(); if (advance < chartlist.size()-1) { advance++; } } private void previousmouseclicked(java.awt.event.mouseevent evt) { if (advance > 0) { advance--; } panelcombination.removeall(); panelcombination.add(chartlist.get(advance)); panelcombination.validate(); }
use cardlayout change views, instead of trying remove , add panels. you're trying can accomplished calling next() , previous() methods of cardlayout. need set layout of panelcombination cardlayout, add panels panelcombination , use methods
cardlayout layout = new cardlayout(); panelcombination.setlayout(layout); // add panels. .... private void previousmouseclicked(java.awt.event.mouseevent evt) { layout.previous(panelcombination); see more @ how use cardlayout
also looks of method signatures, looks using netbeans gui builder. can see how use cardlayout netbeans gui builder
Comments
Post a Comment