Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:34:58+00:00 2026-06-13T07:34:58+00:00

I have a problem with getting text from selected position of JComboBox. I tried

  • 0

I have a problem with getting text from selected position of JComboBox. I tried to use getSelectedItem method in class which extends Kodowanie.java, but i get null value and i can’t find out why. Method (getSelectedItem) works in Kodowanie class I can easily get text form JComboBox .

Kodowanie.java

   public class Kodowanie {

        //Skladowe:
        ArrayList <String> qweqwe; 
        JComboBox inputCode = new JComboBox();  //HERE IS MY INPUT COMBOBOX
        JComboBox outputCode = new JComboBox();
        JTextArea input;
        JTextArea output;

    public void createGUI(){

        JFrame frame = new JFrame("Code");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        input  = new JTextArea(); 
        output = new JTextArea();

        qweqwe = new ArrayList<>();
        napelnijTalbiceCharsetami(qweqwe); //METHOD WHICH ADD ALL CHARSETS TO LIST

        inputCode = new JComboBox(qweqwe.toArray());
        outputCode = new JComboBox(qweqwe.toArray());

        JScrollPane scrollPaneInput = new JScrollPane(input, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        JScrollPane scrollPaneOutput = new JScrollPane(output, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

        scrollPaneInput.setBorder(BorderFactory.createTitledBorder("Input Path"));
        scrollPaneOutput.setBorder(BorderFactory.createTitledBorder("Output Path"));

        inputCode.setPreferredSize(new Dimension(400,50));
        outputCode.setPreferredSize(new Dimension(400,50));

        scrollPaneInput.setPreferredSize(new Dimension(400, 100));
        scrollPaneOutput.setPreferredSize(new Dimension(400, 100));

        input.addKeyListener(new KeyAdapter() {
             public void keyPressed(KeyEvent evt){  
                    Strumieniowanie tmp;
                    if(evt.getKeyCode() == KeyEvent.VK_ENTER)
                    {
                        try {
                            tmp = new Strumieniowanie(input.getText(), output.getText());
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
        });

        frame.getContentPane().add(scrollPaneInput);
        frame.getContentPane().add(scrollPaneOutput);
        frame.getContentPane().add(inputCode);
        frame.getContentPane().add(outputCode);

        frame.setLayout(new  FlowLayout());
        frame.setPreferredSize(new Dimension(850, 220));
        frame.setVisible(true);
        frame.pack();

    }

    private ArrayList napelnijTalbiceCharsetami(ArrayList tmp){
        Map charSets = Charset.availableCharsets();
        Iterator iterator = charSets.keySet().iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next().toString());
            tmp.add(iterator.next().toString());
        }
        return tmp;
    }



    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Kodowanie l = new Kodowanie();
        l.createGUI();
    }



}

Strumieniowanie.java

public class Strumieniowanie extends Kodowanie {

    protected boolean pathInputOk = false;
    protected boolean pathOutputOk = false;

public Strumieniowanie(String tmpInpute, String tmpOutput) throws IOException {


    File plikInput = new File(tmpInpute);
    File plikOutput = new File(tmpOutput);

    String inputText;
    inputText =  (String) inputCode.getSelectedItem(); //HERE I TRY TO GET STRING FROM JCOMBOBOX BUT IT IS ALWAYS NULL !
    System.out.println(inputText);

    pathInputOk = plikInput.isFile();
    pathOutputOk = plikOutput.isFile();

    System.out.println(pathInputOk);
    System.out.println(pathOutputOk);

    if (pathInputOk && pathOutputOk) {
        File nowyPlik = new File(tmpInpute);

        FileInputStream fis = new FileInputStream(nowyPlik);

        fis.close();

    }

}

protected boolean isItaPath(File plik) {
    boolean tmp = 

false;
        tmp = plik.isFile();

        return tmp;
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:34:59+00:00Added an answer on June 13, 2026 at 7:34 am

    KeyListener is not the appropriate event listener to use, it is triggered BEFORE the combobox has updated its state, better to use an ActionListener.

    The actionPerformed event will be fired AFTER the combo box has updated, which will ensure that the getSelectedItem method will actually return the currently selected value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem getting text from edittext inside listview when im in last edittext
I have no problem getting a value from a text box with some id:
I have problem with getting values from select option when use JQuery UI $('#id').combobox().
I have a problem with getting text from EditText field to insert it in
I have a problem getting a private method using reflection. Even with BindingFlags.NonPublic and
I have a problem with getting jquery to retrieve results from a WCF service.
I'm having some problem getting text with special characters (Swedish: åäö) from the database.
if I have set text in textview in such way, which is not problem:
I have a problem getting an inputed date (yyyyMMdd) from an HTML form to
I have a TextView which I fill with text from a string resources in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.