Loading...
Logo
Processing Forum
Hi,

I'm using controlP5 for the first time and am trying to populate the fields of the ListBox's ListBoxItems. What I want to do is change the background of each listboxitem to a color that I have already defined in a String[], I then want to populate the textfield of each item with the name of a country that I have also stored in another array.

For some reason, the background of each listboxitem changes perfectly, but the text will not show up. It won't even show up if I pass it a something static like "dog"... I don't know what to do, I've tried everything! I've made sure to check that there is nothing masking the locaiton of the ListBox, so that it's not being drawn over, since I setup the ListBox in setup().

It's especially strange because the ListBox example from the cp5 library has the listboxitems loading text just fine!

Any help is appreciated!



Replies(4)



void setup() {
  size(displayResolutionX, displayResolutionY);
  colorMode(HSB, 360, 100, 100);
  frameRate(30);
  smooth();
  
  bg = loadImage("Gradient_Background.jpg");
  bg.resize(displayResolutionX, displayResolutionY);
  image(bg, 0, 0);
   
  unitsOfMeasure[0] ="Quadrillion\nBtu";
  unitsOfMeasure[1] ="Quadrillion\nBtu";
  unitsOfMeasure[2] ="Million\nBtu\nper Person";
  unitsOfMeasure[3] ="Million\nMetric\nTons";
  unitsOfMeasure[4] ="Metric Tons\nof CO2\nper Person";
  unitsOfMeasure[5] ="Billion\nKilowatt\nHours";
  
  background(315);
  
  //Define important data members first:
  data = new EntryTable("Total_Primary_Energy_Production_(Quadrillion_Btu).txt");
  rowCount = data.getRowCount();
  columnCount = data.getColumnCount();
  
  years = int(data.getColumnNames());
  yearMin = years[0];
  yearMax = years[columnCount - 1];
  
  countries = data.getRowNames();
  
  dataMin = 0;
  dataMax = ceil(data.getTableMax() / roundAway) * roundAway;
  
  graphMax = dataMax + (dataMax * 0.1);
  
  showCountries = new boolean[countries.length];
    
  colorsOfCountries= new color[rowCount];
  colorCodeCountries();
  
  data.calculateSortSumData();
  arrayOfSmallestAreas = data.sumData;
  
  //Sets up initial Integrators for the default graph thats loaded
  interpolators = new Integrator[rowCount][columnCount];
  for(int row = 0; row < rowCount; row++){
    for(int col = 0; col < columnCount; col++){
      float initialValue = float(data.getEntry(row, col));
      interpolators[row][col] = new Integrator(initialValue);
      interpolators[row][col].attraction = 0.1; //Set lower than default
      
      showCountries[row] = true;
      }
    }
  
  configureYMarkers();
    
  plotFont = createFont("Gulim", 8);  
  tabFont = createFont("Gulim", 12);    
  axisUnitFont = createFont("Cordia New", 24);  
  axisLabelFont = createFont("Euphimia", 30);  
  countryFont = createFont("Gulim", 20);  
  
  graphPlotX1 = width * 0.35; 
  graphPlotX2 = width - (0.01 * width);
  axisLabelY = graphPlotX1 - (0.08 *width);
  graphPlotY1 = 60;
  graphPlotY2 = height - 120;
  axisLabelX = height - 25;
  
  filterGraphPlotX1 = int(.01 * width);
  filterGraphPlotY1 = int(graphPlotY1 - (.03 * width));
  filterGraphPlotX2 = int(graphPlotX1 - (.15 * width));
  filterGraphPlotY2 = int(graphPlotY2);
  
  filterLabelX = filterGraphPlotX1 + 10;
  filterLabelY = filterGraphPlotY1 + 10;
  
  cp5 = new ControlP5(this);// TEXT WONT POPULATE THE LISTBOXITEMS!!!!!!!  
  l = cp5.addListBox("myList")
                 .setPosition(filterGraphPlotX1, (filterGraphPlotY1 + 35))
                 .setSize((filterGraphPlotX2 - filterGraphPlotX1), (filterGraphPlotY2 - filterGraphPlotY1))
                 .setItemHeight(20)
                 .setBarHeight(35)
                 .setColorBackground(color(250))
                 .setColorActive(color(330))
                 ;
                 
  l.captionLabel().toUpperCase(true);
  l.captionLabel().set("Filter by Country:");
  l.captionLabel().setColor(#020208);
  l.captionLabel().style().marginTop = 3;
  l.valueLabel().style().marginTop = 3;
  
    for(int i = 0; i < rowCount; i++){ 
    ListBoxItem lbi = l.addItem(countries[i], i);
    lbi.setColorBackground(colorsOfCountries[i]);
  }
  
  range = cp5.addRange("rangeController")
             // disable broadcasting since setRange and setRangeValues will trigger an event
             .setBroadcast(false) 
             .setPosition(graphPlotX1, (graphPlotY2+45))
             .setSize(int(graphPlotX2 - graphPlotX1),10)
             .setHandleSize(20)
             .setRange(0, 29)
             .setRangeValues(0,29)
             // after the initialization we turn broadcast back on again
             .setBroadcast(true)
             .setColorForeground(color(75,360))
             .setColorBackground(color(180,180))  
             .setNumberOfTickMarks(30)
             ;
  
  }
  


void draw(){
background(315);
  
noStroke();
fill(350);
rectMode(CORNERS);
rect(graphPlotX1, graphPlotY1, graphPlotX2, graphPlotY2);
 
drawTitleTabs();
drawAxisLabels();

for(int row = 0; row <rowCount; row++){
  for(int col = 0; col < columnCount; col++){
  interpolators[row][col].update();            
  }
 }
  drawYearLabels();
  drawDataArea();
  drawVerticalAndHorizontalLabels();
}

Hi, some sample code would be helpful here to assist you. in case your code is very long, please only paste the relevant sections.
Well, that was the problem; I don't know what ordering of the code would result in me not being able to see text from cp5 controllers. I figured it out though. I had defined my ControlP5 object below a custom colorMode. The problem was fixed as soon as I declared my cp5 before the colorMode.
Sorry about the spam-engine. To quote PhiLho, "It is better known for its false positives than for its reporting of spam". The spam-engine found the word "million" (but not "billion", apparently) and decided that your response was spam. Your most recent code has been restored.