0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Processing > ControlP5 > ListBox > クリックイベントが発生しない

Last updated at Posted at 2016-07-17
動作環境
Processing 3.1.1 on Windows 8.1 pro(64bit)
Library: ControlP5 v2.2.6

以下のListBoxの実装を試したが、Event1, Event2ともに発生しない。

import controlP5.*;

ControlP5 controlP5;

int myCurrentIndex = 0;
String[] tokens;

void setup() {
  size(500,500);
  frameRate(10);
  controlP5 = new ControlP5(this);
  ListBox lst = controlP5.addListBox("myList", 20, 40, 80, 200);
  
  tokens = new String[10];
  tokens[0] = "Hello";
  tokens[1] = "Hi";
  tokens[2] = "Ca va bien?";
  lst.addItem(tokens[0], 0);
  lst.addItem(tokens[1], 1);
  lst.addItem(tokens[2], 2);
}

void controlEvent(ControlEvent theEvent) {  
  if (theEvent.isGroup()) {
    println("Event1");
    println(theEvent.getGroup().getValue() + " from " + theEvent.getGroup());
  }

  if (theEvent.isGroup() && theEvent.getName().equals("myList")) {
    println("Event2");
    myCurrentIndex = (int)theEvent.getGroup().getValue();
  }
}

void draw() {
  background(0);
  
  fill(255);
  if (myCurrentIndex >= 0) {
    text(tokens[myCurrentIndex], 200, 40);
  }
}

I guess ListBox is also depreciated and they recommend you use scrollableList instead.

リンク先のリンク先のjavadocを見てもListBox がdepreciated というのは見つかってはいないが、scrollableList で代用できるのであればそれでいい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?