我在使用gridpane调整列表框大小时遇到了一些问题。可能吗??我需要一个比一条线大的实际矩形盒子。我真的希望这是可能的,如果你不能请你给我一些指示。我是新手,并且已经在这方面工作了一段时间。任何帮助将不胜感激。谢谢!!
我尝试过的是没有用的 -
list.setPrefWidth(100);
list.setPrefHeight(200);
package application;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
// Pane pane = new Pane();
GridPane pane = new GridPane();
pane.setAlignment(Pos.TOP_LEFT);
pane.setPadding(new Insets(20, 20, 20, 20));
pane.setHgap(5.5);
pane.setVgap(5.5);
final ComboBox<String> beverageComboBox = new ComboBox<String>();
beverageComboBox.getItems().addAll("Soda ", "Tea", "Coffee", "Mineral Water", "Juice",
"Milk");
final ComboBox<String> appetizerComboBox = new ComboBox<String>();
appetizerComboBox.getItems().addAll("Buffalo Wings ", "Buffalo Fingers", "Potato Skins", "Nachos",
"Mushroom Caps", "Shrimp Cocktail");
final ComboBox<String> maincourseComboBox = new ComboBox<String>();
maincourseComboBox.getItems().addAll("Seafood Alfredo ", "Chicken Alfredo", "Chicken Picatta", "Turkey Club",
"Lobster Pie", "Prime Rib", "Shrimp Scampi", "Turkey Dinner", "Stuffed Chicken");
final ComboBox<String> dessertComboBox = new ComboBox<String>();
dessertComboBox.getItems().addAll("Apple Pie ", "Sundae", "Carrot Cake", "Mud Pie", "Apple Crisp");
/*
* beverageComboBox.setValue("Soda"); appetizerComboB(ox.setValue(
* "Buffalo Wings"); maincourseComboBox.setValue("Seafood Alfredo");
* dessertComboBox.setValue("Apple Pie");
*/
Image image = new Image("fd.jpg");
pane.getChildren().add(new ImageView(image));
// -----------------------------------------------------------------------------------------------------------
Label tit = new Label("John's");
tit.setFont(Font.font("Tahoma", FontWeight.BOLD, 32));
pane.add(tit, 1, 0);
// ---------------------------------------------------------------------------------------------------------------
Label wi = new Label("Waiter Information");
wi.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
pane.add(wi, 0, 5);
Label tn = new Label("Table Number:");
pane.add(tn, 0, 6);
TextField tnf = new TextField();
pane.add(tnf, 1, 6);
Label wn = new Label("Waiter's Name:");
pane.add(wn, 0, 7);
TextField twn = new TextField();
pane.add(twn, 1, 7);
// ---------------------------------------------------------------------------------------------------------
Label mi = new Label("Menu Items");
mi.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
pane.add(mi, 0, 10);
Label b = new Label("Beverage:");
pane.add(b, 0, 11);
pane.add(beverageComboBox, 1, 11);
Label a = new Label("Appetizer:");
pane.add(a, 0, 12);
pane.add(appetizerComboBox, 1, 12);
Label mc = new Label("Main Course:");
pane.add(mc, 0, 13);
pane.add(maincourseComboBox, 1, 13);
Label d = new Label("Dessert:");
pane.add(d, 0, 14);
pane.add(dessertComboBox, 1, 14);
// ----------------------------------------------------------------------------------------------------------
Label bi = new Label("Bill");
bi.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
pane.add(bi, 0, 17);
Label st = new Label("Subtotal:");
pane.add(st, 0, 18);
TextField tst = new TextField();
pane.add(tst, 1, 18);
Label t = new Label("Tax:");
pane.add(t, 0, 19);
TextField tt = new TextField();
pane.add(tt, 1, 19);
Label to = new Label("Total:");
pane.add(to, 0, 20);
TextField tto = new TextField();
pane.add(tto, 1, 20);
// -----------------------------------------------------------------------------------------------------------
Label w = new Label("Waiter:");
pane.add(w, 0, 23);
TextField tw = new TextField();
pane.add(tw, 1, 23);
Label tn2 = new Label("Table Num:");
pane.add(tn2, 0, 24);
TextField ttn = new TextField();
pane.add(ttn, 1, 24);
// ------------------------------------------------------------------------------------------------------------
Button btn = new Button(" Clear Bill ");
pane.add(btn, 1, 30);
// -------------------------------------------------------------------------------------------------------------
Label io = new Label("Items Ordered");
io.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
pane.add(io, 2, 3);
// -----------------------------------------------------------------------------------------------------------------------
Label bo = new Label("Beverage Ordered");
pane.add(bo, 2, 5);
ListView<String> list = new ListView<>();
ObservableList<String> items = FXCollections.observableArrayList();
list.setItems(items);
pane.add(list, 3, 5);
// ---------------------------------------------------------------------------------------------------------------
Label ao = new Label("Appetizer Ordered");
pane.add(ao, 2, 7);
ListView<String> list2 = new ListView<>();
ObservableList<String> items2 = FXCollections.observableArrayList();
list2.setItems(items2);
pane.add(list2, 3, 7);
// ----------------------------------------------------------------------------------------------------------------
Label mco = new Label("Main Course Ordered");
pane.add(mco, 2, 11);
ListView<String> list3 = new ListView<>();
ObservableList<String> items3 = FXCollections.observableArrayList();
list3.setItems(items3);
pane.add(list3, 3, 11);
// -------------------------------------------------------------------------------------------------------------------
Label od = new Label("Dessert Ordered");
pane.add(od, 2, 13);
ListView<String> list4 = new ListView<>();
ObservableList<String> items4 = FXCollections.observableArrayList();
list4.setItems(items4);
pane.add(list4, 3, 13);
// Create a new scene and place it in the stage
Scene scene = new Scene(pane, 800, 800);
primaryStage.setTitle("Restaurant Bill Calculator");
primaryStage.setScene(scene);
primaryStage.show();
}
}