亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么按鈕在點擊時調整大小

為什么按鈕在點擊時調整大小

瀟湘沐 2023-03-17 14:22:53
我正在做一個簡單的計算器,問題出在按鈕上。當我點擊它們時,它們在底部略微收縮,這是我不想做的。此外,當我單擊 textArea 時,白點消失了,但是當我單擊按鈕時,textArea 周圍的點再次顯示。為什么?如何使它們永久不可見?我試圖在 .button:pressed 代碼中放入 css,將按鈕的大小設置為正常大小,但它不起作用。無論如何,它們正在縮小。Main.javapackage gui;public class Main {    public static void main(String[] args){Calculator.main(args);}}樣式.css.root{    -fx-background-color: #000;    -fx-background-radius: 10;}#screen{    -fx-pref-height: 150px;    -fx-pref-width: 230px;    -fx-control-inner-background: #000000;    -fx-focus-color: #000000;    -fx-text-box-border: #000000;    -fx-background-color: #000000;    -fx-focus-color: black;    -fx-faint-focus-color: black;    -fx-text-box-border: black;}.button{    -fx-pref-height: 50px;    -fx-pref-width: 50px;    -fx-background-radius: 100;    -fx-font-size: 15;    -fx-font-Weight: bold;    -fx-background-color: #333333;    -fx-text-fill: #FFFFFF;}.button:hover{    -fx-background-color: #3d3d3d;}.button:pressed{    -fx-background-color: #2e2e2e;}#button0{    -fx-pref-height: 50px;    -fx-pref-width: 110px;}#buttonPercent, #buttonClear, #buttonSign{    -fx-background-color: #A5A5A5;    -fx-text-fill: #000000;}#buttonPercent:hover, #buttonClear:hover, #buttonSign:hover{    -fx-background-color: #b0b0b0;    -fx-text-fill: #000000;}#buttonPercent:pressed, #buttonClear:pressed, #buttonSign:pressed{    -fx-background-color: #969696;    -fx-text-fill: #000000;}#buttonDevide, #buttonTimes, #buttonMinus, #buttonPlus, #buttonEqual{    -fx-background-color: #FD9500;}#buttonDevide:hover, #buttonTimes:hover, #buttonMinus:hover, #buttonPlus:hover, #buttonEqual:hover{    -fx-background-color: #ffa421;}#buttonDevide:pressed, #buttonTimes:pressed, #buttonMinus:pressed, #buttonPlus:pressed, #buttonEqual:pressed{    -fx-background-color: #f08e00;}#buttonClose{    -fx-background-color: #e00000;    -fx-background-radius: 100;    -fx-pref-height: 10px;    -fx-pref-width: 10px;    -fx-font-size: 1px;}
查看完整描述

1 回答

?
蝴蝶不菲

TA貢獻1810條經驗 獲得超4個贊

要刪除此按鈕效果,請將其添加到 Style.css 中的 .button

    -fx-background-insets: 0 0 -1 0, 0, 1, 2;

在這里閱讀

要刪除 textArea 角中的黑點,您可以將屏幕包裹到 Pane 中:

    Pane blackPane = new Pane();

    blackPane.setId("blackPane");

    screen = new TextArea();

    screen.setId("screen");

    screen.setEditable(false);

    blackPane.getChildren().add(screen);

    gridPane.add(blackPane, 0, row, 4, 1);

并添加 CSS 屬性:


    #blackPane #screen {

    -fx-background-color: black;

    -fx-background-radius: 0;

    }

再次閱讀這里

對我來說效果很好。

以及未來的一些提示:

  • 不要將視圖層與控制層混合,這會使您的代碼變得一團糟。添加 .fxml 文件,您可以在其中創建視圖。您可以使用Scene Builder以清晰的方式輕松構建視圖。

  • 閱讀并執行您的 IDE(推薦的 Intellij)的建議。你有很多重復和復雜的、錯誤的代碼格式。例如:

stackPane.setOnMousePressed(new EventHandler<MouseEvent>() {

    @Override

    public void handle(MouseEvent mouseEvent) {

        // record a delta distance for the drag and drop operation.

        dragDelta.x = primaryStage.getX() - mouseEvent.getScreenX();

        dragDelta.y = primaryStage.getY() - mouseEvent.getScreenY();

    }

});

可以用這個代替:


stackPane.setOnMousePressed(mouseEvent -> {

            // record a delta distance for the drag and drop operation.

            dragDelta.x = primaryStage.getX() - mouseEvent.getScreenX();

            dragDelta.y = primaryStage.getY() - mouseEvent.getScreenY();

        });


查看完整回答
反對 回復 2023-03-17
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號