I am using processing to display a number of buttons with the ControlP5 API. At the moment I can get the buttons to display in the window of the sketch but when I resize the frame the button positions do not update, Is there a simple way to redraw the buttons in order to re-position them automatically when a window is resized or am I wasting my time?
Here is the code:
package controlp5userinterface;
import java.awt.event.*;
import java.util.ArrayList;
import processing.core.PApplet;
import processing.core.PImage;
import controlP5.*;
public class ControlP5UserInterface extends PApplet {
ControlP5 controlP5;
PImage bg;
Controller b;
@SuppressWarnings("deprecation")
public void setup() {
size(1000,1000);
smooth();
if (frame != null) {
frame.setResizable(true);
}
bg = loadImage("StockBackground1.jpg");
/*
*
* BEGIN CONTROL P5 MENU GENERATION
* buttons will spread out to fit available screen space
*/
controlP5 = new ControlP5(this);
ArrayList<Button> buttons = new ArrayList<Button>();
Group MainMenu = controlP5.addGroup("MainMenu");
MainMenu.setSize(100, 100);
//controlP5.addGroup("MainMenu");
controlP5.addButton("SIMON").setGroup("MainMenu").setSize(80, 50);
controlP5.addButton("ACN").setGroup("MainMenu").setSize(80, 50);
controlP5.addButton("GOOG").setGroup("MainMenu").setSize(80, 50);
//buttons.add(controlP5.addButton("AAPL").setGroup("MainMenu"));
//buttons.add(controlP5.addButton("ACN").setGroup("MainMenu"));
//controlP5.getGroup("MainMenu").setSize(300, 300);
}
/*
*
* SCREEN RESIZE CONTROLLER HERE??(non-Javadoc)
* @see processing.core.PApplet#draw()
*
*/
public void draw() {
background(0); // background black
controlP5.getGroup("MainMenu").update();
}
public int sketchWidth(){
return displayWidth;
}
public int sketchHeight(){
return displayHeight;
}
public static void main(String _args[]) {
PApplet.main(new String[] { controlp5userinterface.ControlP5UserInterface.class.getName() });
}
}