Java help එකක්..

jennt

Well-known member
  • Sep 23, 2021
    3,072
    4,721
    113
    Abyss
    Java:
    public void actionFontSize(ContextMenuEvent inputMethodEvent) {
    //        txtMsg.setFont(Font.font("Times New Roman", fw, fp, (double) cbxFontSize.getValue()));
    //        choiceBox.setOnAction((event) -> {
                int selectedIndex = cbxFontSize.getSelectionModel().getSelectedIndex();
                Object selectedItem = cbxFontSize.getSelectionModel().getSelectedItem();
    
                System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
                System.out.println("   ChoiceBox.getValue(): " + cbxFontSize.getValue());
    
                if (selectedIndex == 1) txtMsg.setFont(new Font(10));
                if (selectedIndex == 2) txtMsg.setFont(new Font(20));
                if (selectedIndex == 3) txtMsg.setFont(new Font(30));
                if (selectedIndex == 4) txtMsg.setFont(new Font(40));
    
    
    //        txtMsg.setFont(new Font("Times New Roman", 10));
    //        String value = (String) cbxFontSize.getValue();
    //        txtMsg.setFont(new Font("Times New Roman", Double.parseDouble(value))); ----- මේ වගේ කරන්න බැරි ඇයි?
    //        });
        }

    Choice box value එක index එකෙන් access කරන්නේ නැතුව
    කෙලින්ම value එක විතරක් ගන්න විදිහක් නැද්ද double value එකක් විදිහට ?

    මෝඩ ප්‍රශ්නයක් වෙන්න ඇති ඒත් හොයා ගන්න බැරි වුණා.
     

    HAneo

    Well-known member
  • Jan 30, 2007
    12,970
    29,168
    113
    Homagama
    Choice box value එක index එකෙන් access කරන්නේ නැතුව
    කෙලින්ම value එක විතරක් ගන්න විදිහක් නැද්ද double value එකක් විදිහට ?

    මෝඩ ප්‍රශ්නයක් වෙන්න ඇති ඒත් හොයා ගන්න බැරි වුණා.
    Code:
     cbxFontSize.getValue()
    (to get the value that the user selects from the ChoiceBox)

    oken enne ekane? type cast karala ganna thiyenne?

    OR uba ahala thiyana eka pahadili na
     
    • Like
    Reactions: Stimulus mind

    jennt

    Well-known member
  • Sep 23, 2021
    3,072
    4,721
    113
    Abyss
    cbxFontSize.getValue()
    ඕකෙන් output එක විදිහට එන්නෙ object එකක් නේ.. ඒක් double value එකක් විදිහට ගන්න බැරිද?

    1655895311017.png


    cbxFontSize කියන choice box එකේ value එක change කරද්දි txtMsg කියන එකේ font size වෙනස් වෙන්න හදන්න ඕන .
     

    HAneo

    Well-known member
  • Jan 30, 2007
    12,970
    29,168
    113
    Homagama
    ඕකෙන් output එක විදිහට එන්නෙ object එකක් නේ.. ඒක් double value එකක් විදිහට ගන්න බැරිද?

    View attachment 175139

    cbxFontSize කියන choice box එකේ value එක change කරද්දි txtMsg කියන එකේ font size වෙනස් වෙන්න හදන්න ඕන .
    cbxFontSize eka hadapu thana pennapan

    ekata uba object type ekak bind karala nathnam Cast karala ganin


    Code:
    String value = (<Type>) choiceBox.getValue();
     

    Musk99

    Junior member
  • Apr 9, 2021
    45
    39
    18
    Choice box value එක index එකෙන් access කරන්නේ නැතුව
    කෙලින්ම value එක විතරක් ගන්න විදිහක් නැද්ද double value එකක් විදිහට ?

    මෝඩ ප්‍රශ්නයක් වෙන්න ඇති ඒත් හොයා ගන්න බැරි වුණා.
    System.out.println(" ChoiceBox.getValue(): " + cbxFontSize.getValue());
    `what is the output here ?