G4P - GSlider

edited December 2013 in Library Questions

If i have a program with more than one window, how can i show the slider in just one of those windows?
I tried to call it inside a PGraphics, but the constructor requires a PApplet. If i use this, the slider appears on all of the windows... I tried too to call the slider only when i'm in the windown i want, but slider doesn't work if created in draw(), only in setup()...
Any thoughts? Thanks ;)

Tagged:

Answers

  • edited December 2013

    The easiest way to create GUIs with G4P is to use the GUI Builder tool (Tools | Add Tool menu option) but if you have already created your sketch then the code below shows how to create a second window and add a slider to it.

    import g4p_controls.*;
    
    // Variable declarations 
    GWindow window1;
    GSlider slider1; 
    
    
    public void setup(){
      size(480, 320, JAVA2D);
      createGUI();
    
    }
    
    public void draw(){
      background(230);
    
    }
    
    // Create all the GUI controls. 
    public void createGUI(){
      G4P.messagesEnabled(false);
      G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
      G4P.setCursor(ARROW);
      window1 = new GWindow(this, "Window title", 0, 0, 240, 120, false, JAVA2D);
      window1.addDrawHandler(this, "win_draw1");
      slider1 = new GSlider(window1.papplet, 70, 40, 100, 40, 10.0);
      slider1.setLimits(0.5, 0.0, 1.0);
      slider1.setNumberFormat(G4P.DECIMAL, 2);
      slider1.setOpaque(false);
      slider1.addEventHandler(this, "slider1_change1");
    }
    
    synchronized public void win_draw1(GWinApplet appc, GWinData data) {
      appc.background(230);
    }
    
    // Handle events for slider1
    public void slider1_change1(GSlider source, GEvent event) {
      println("slider1 - GSlider event occured " + System.currentTimeMillis()%10000000 );
    }
    
  • GUI Builder tool makes very easy! Thanks

    But i think i didn't express myself very well...When i said "window", actually i meant more like a page... The program has only one window, but there are several diferent pages, or tabs...
    The problem is that i call createGUI(); in setup(), so the slider appears in all of the pages...
    Sorry about the misunderstanding...

  • Answer ✓

    Simply show / hide the slider when required with

    slider1.setVisible(true);

    slider1.setVisible(false);

Sign In or Register to comment.