首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不能点击按钮

我不能点击按钮
EN

Stack Overflow用户
提问于 2019-08-28 00:37:02
回答 2查看 91关注 0票数 0

我正在制作一个销售系统,在描述总金额的区域,我不能点击按钮。

我试图从网格窗格中删除按钮,但当我将它们集成到网格窗格中时,它们会失去焦点或停止工作

代码语言:javascript
复制
Pane root = new Pane();

Separator top = new Separator(Orientation.HORIZONTAL);
top.setPrefWidth(1310);

Separator left = new Separator(Orientation.VERTICAL);
left.setPrefHeight(150);

left.setPadding(new Insets(0,0,10,0));
Separator low = new Separator(Orientation.HORIZONTAL);

low.setPadding(new Insets(140,10,0,0));
low.setPrefWidth(1323);

Separator right = new Separator(Orientation.VERTICAL);
right.setPrefHeight(150);

right.setPadding(new Insets(0,0,10,1310));


Label descuento = new Label("Descuento: ");

Label sub = new Label("Sub-Total: ");

Label iva = new Label("Iva: ");

Label total = new Label("Total: ");

Label rsub = new Label("0000.00");

Label riva= new Label("16%");

Label rtotal = new Label("0.0000");


Button btn_generate = new Button("generate");

MenuItem opc = new MenuItem("Opc");
MenuItem opc1= new MenuItem("opc1");

MenuButton menu1 = new MenuButton("Type",null,opc,opc1);

MenuItem opc2 = new MenuItem("opc2");
MenuItem opc3 = new MenuItem("opc3");

MenuButton menu2 = new MenuButton("Opc",null,opc2,opc3);


GridPane Gtotal = new GridPane();

Gtotal.setHgap(20);
Gtotal.setVgap(10);
Gtotal.setPadding(new Insets(10,0,0,10));

ColumnConstraints column1 = new ColumnConstraints(rtotal.getPrefWidth(),rtotal.getPrefWidth(),rtotal.getPrefWidth());
ColumnConstraints column2 = new ColumnConstraints(total.getPrefWidth()+450,total.getPrefWidth()+450,total.getPrefWidth()+450);
ColumnConstraints column3 = new ColumnConstraints(riva.getPrefWidth(),riva.getPrefWidth(),riva.getPrefWidth());
ColumnConstraints column4 = new ColumnConstraints(iva.getPrefWidth()+330,iva.getPrefWidth()+330,iva.getPrefWidth()+330);
ColumnConstraints column5 = new ColumnConstraints(rsub.getPrefWidth(),rsub.getPrefWidth(),rsub.getPrefWidth());
ColumnConstraints column6 = new ColumnConstraints(sub.getPrefWidth(),sub.getPrefWidth(),sub.getPrefWidth());

Gtotal.getColumnConstraints().add(0,column1);
Gtotal.getColumnConstraints().add(0,column2);
Gtotal.getColumnConstraints().add(0,column3);
Gtotal.getColumnConstraints().add(0,column4);
Gtotal.getColumnConstraints().add(0,column5);
Gtotal.getColumnConstraints().add(0,column6);

GridPane.setConstraints(descuento, 0, 0);
GridPane.setConstraints(menu1, 1, 0);
GridPane.setConstraints(menu2, 2, 0);
GridPane.setConstraints(sub, 0, 1);
GridPane.setConstraints(rsub, 1, 1);

GridPane.setConstraints(iva, 2, 1);
GridPane.setHalignment(iva, HPos.RIGHT);

GridPane.setConstraints(riva, 3, 1);

GridPane.setConstraints(total, 4, 1);
GridPane.setHalignment(total, HPos.RIGHT);

GridPane.setConstraints(rtotal, 5, 1);
GridPane.setConstraints(btn_generate, 5, 2);

Gtotal.getChildren().addAll(descuento,sub,rsub,iva,riva,total,rtotal,btn_generate,menu1,menu2);

root.getChildren().addAll(top,left,Gtotal,low,right);

Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();

我希望在运行该程序时,可以单击这些按钮。

EN

回答 2

Stack Overflow用户

发布于 2019-09-12 23:02:47

Marcos Antonio你真的是在为自己做工作,而不是使用Scene Builder

也就是说,这里有3行代码可以让按钮触发一个事件

代码语言:javascript
复制
    Button btnOK = new Button("OK");
    btnOK.addEventHandler(ActionEvent.ACTION,filter);
    btnOK.setOnAction((ActionEvent evt) -> {
票数 0
EN

Stack Overflow用户

发布于 2019-09-13 23:54:55

问题是分隔符通过填充与其他布局重叠。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57679002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档