'u kullanarak bir açılır kutu nasıl oluşturulur? Aşağıdaki kod, düğmelerle doldurulmuş bir Kılavuz oluşturur. Birisi üzerinde başka bir ızgara kutusu açan bir yöntemi nasıl ekleyebileceğini bilmek isterim. İkinci açılan ızgara kutusundaki sayı seçildiğinde, tıklanan orijinal düğmedeki etiketi değiştirir. Aşağıdaki örnekte, birisi "1" metnini içeren düğmeye basar. Bir ızgara 1 ila 5 arasında etiketli düğmelerle açılır. Düğme 5 tıklanır. Açılır pencere kutusu kaybolur ve üzerinde "1" yazan düğme şimdi "5" olarak değiştirilir.JavaFX
import javafx.application.*;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
public class GUI extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override public void start(Stage primaryStage)
{
final int HGAP = 2;
final int VGAP = 2;
final int BUTTONSIZE = 50;
final int INSET = 5;
final int SIZE = 4;
GridPane root = new GridPane();
root.setPadding(new Insets(INSET));
root.setHgap(HGAP);
root.setVgap(VGAP);
root.setAlignment(Pos.CENTER);
final Button[][] btn = new Button[SIZE][SIZE];
final Paint background = Color.TURQUOISE;
int index = 0;
for (int theCol = 0; theCol < SIZE; theCol++) {
for (int theRow = 0; theRow < SIZE; theRow++) {
btn[theRow][theCol] = new Button(""+ index);
btn[theRow][theCol].setPrefSize(BUTTONSIZE, BUTTONSIZE);
root.add(btn[theRow][theCol], theRow, theCol);
index++;
btn[theRow][theCol].setOnMouseClicked(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent arg0)
{
Button b= (Button)arg0.getSource();
System.out.println(b.getText());
}
});
}
}
Scene scene = new Scene(root,background);
primaryStage.setTitle("Grid");
primaryStage.setScene(scene);
primaryStage.show();
}
}
Sanırım burada açıklanmıştır: http://stackoverflow.com/questions/12717969/javafx-2-custom-popup-pane – DVarga
Bence buradaki linklerden bazılarında kod örnekleri olan geçici bağlantılar vardı. – StonedRanger