Saturday, November 7, 2015

JavaFx Tutorial For Beginners 12 - JavaFX ComboBox













package application;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
 @Override
 public void start(Stage primaryStage) {
  try {
   Parent root = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
   Scene scene = new Scene(root);
   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
   primaryStage.setScene(scene);
   primaryStage.show();
  } catch(Exception e) {
   e.printStackTrace();
  }
 }
 
 public static void main(String[] args) {
  launch(args);
 }
}








package application;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;

public class MainController implements Initializable{
 
 @FXML
 public Label myLabel;
 @FXML
 public ComboBox<String> combobox;
 
 ObservableList<String> list = FXCollections.observableArrayList("Mark","Tom", "John","Jack");
 @Override
 public void initialize(URL location, ResourceBundle resources) {
  // TODO Auto-generated method stub
  //combobox.setItems(list);
  
 }
 
 public void comboChanged(ActionEvent event) {
  combobox.getItems().addAll("Ram","Ben", "STEVE","Ma");
  //myLabel.setText(combobox.getValue());
 }
 
 public void buttenAction(ActionEvent event) {
  combobox.getItems().addAll("Ram","Ben", "STEVE","Ma");
  //myLabel.setText(combobox.getValue());
 }

}












<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<?import javafx.collections.*?>

<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40" fx:controller="application.MainController">
   <children>
      <ComboBox fx:id="combobox" layoutX="75.0" layoutY="108.0" onAction="#comboChanged" prefHeight="51.0" prefWidth="172.0" promptText="Select Name" >
      <items>
      <FXCollections fx:factory="observableArrayList">
          <String fx:value="Item 1" />
          <String fx:value="Item 2" />
          <String fx:value="Item 3" />
          <String fx:value="Item 4" />
      </FXCollections>
      </items>
      </ComboBox>
      <Label fx:id="myLabel" layoutX="75.0" layoutY="44.0" prefHeight="51.0" prefWidth="172.0" text="Label" />
      <Button layoutX="109.0" layoutY="203.0" mnemonicParsing="false" onAction="#buttenAction" text="Button" />
   </children>
</AnchorPane>

















IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ