yılında düğmeden nasıl ekleneceği aşağıda resimdeki gibi remove düğmesi ile bir ComboBox oluşturmak istiyorum:combobox
resim Java Swing kullanır ve ben nasıl yapılacağını bilmiyorum bu JavaFX ile. İki ComboBox (a, b) oluşturmak istiyorum. ComboBox'taki "cross" a tıkladığımda, bir öğeyi kaldırmak ve bu öğeyi ComboBox b'ye ve ComboBox b'ye eklemek istiyorum.
ComboBox a: (1) Daha sonra mal çıkarın ve b
ComboBox b eklemek tıklayın: (1) tıklayın madde daha sonra yapılacak bir şey (örn: Baskı öğesi)
(2) ardından çapraz tıklayın b çıkarın ve bir
eklentipackage UnitTest;
import Peer.Peer_Manager;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.chart.XYChart;
import javafx.geometry.Insets;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
public class temp extends Application {
final int height = 200;
final int weight = 300;
final int offset = 5;
Peer_Manager p_management;
XYChart.Series series_hop;
XYChart.Series series_gd;
@Override
public void start(Stage primaryStage) {
VBox vbox = new VBox();
vbox.setPadding(new Insets(5, 5, 5, 5));
vbox.setStyle("-fx-background-color: CORNSILK;");
Scene scene = new Scene(vbox, weight, height);
primaryStage.setScene(scene);
HBox hbBtn = new HBox();
Text t1=new Text(" A:");
Text t2=new Text(" B:");
String[] filename = {"A","B","C"};//conf.load_all();
ComboBox<String> cb = new ComboBox<String>();
cb.setItems(FXCollections.observableArrayList(filename));
cb.setVisibleRowCount(10);
ComboBox<String> cb2 = new ComboBox<String>();
cb.setVisibleRowCount(10);
vbox.getChildren().add(hbBtn);
hbBtn.getChildren().add(t1);
hbBtn.getChildren().add(cb);
hbBtn.getChildren().add(t2);
hbBtn.getChildren().add(cb2);
cb.setOnAction(e -> {
try {
Object object = cb.getValue();
if (object != null) {
cb2.getItems().add(object);
cb.getSelectionModel().clearSelection();
cb.getItems().remove(object);
}
} catch (Exception e1) {
e1.printStackTrace();
}
});
//would like to do something(ex:print item),but don't remove
//add the "cross" beside items,click "cross" to remove item and add on cb
cb2.setOnAction(e -> {
try {
Object object = cb2.getValue();
System.out.println(object);
if (object != null) {
cb1.getItems().add(object);
cb2.getSelectionModel().clearSelection();
cb2.getItems().remove(object);
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
});
primaryStage.setTitle("SimulatorFX");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Hiç bir kodunuz var mı? – Joris
Lütfen sorunuz [değiştir] ve sorun yaşadığınız şeyin bir [mcve] bölümünü ekleyin. –
ControlsFX'ten [CheckComboBox] (http://fxexperience.com/controlsfx/features/#checked) adresini ziyaret edebilirsiniz. – Itai