0

I'm adding a JLabel (pop_up) to a JFrame, but it doesn't show until the frame is resized.The program is to get users inputs for different search functions. The bit I'm struggling on is the below, as the pop_up JLabel isn't showing.

enter.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if(table_search.getText().equals("Table") || column.getText().equals("Column") || search.getText().equals("Search")) {
                    JLabel pop_up = new JLabel("You haven't changed one or more of the text fields.");
                    pop_up.setBounds(240, 184, 350, 40);
                    frame.add(pop_up);

                }
                else {
                    String txtTable = table_search.getText();
                    String txtColumn = column.getText();
                    String txtSearch = search.getText();

                    table_search.setText("");
                    column.setText("");
                    search.setText("");
                }
            }

        });
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
JacobMoore
  • 13
  • 6
  • 2
    You need to repaint the window – XtremeBaumer Jul 25 '19 at 08:49
  • @XtremeBaumer Can you tell me how to do that? Is it just frame.repaint() ? – JacobMoore Jul 25 '19 at 08:50
  • Possible duplicate of [How can I refresh or reload the JFrame?](https://stackoverflow.com/questions/7628121/how-can-i-refresh-or-reload-the-jframe) – XtremeBaumer Jul 25 '19 at 08:57
  • Thanks @XtremeBaumer, that does answer my question. I didn't know that I had to refresh or reload the JFrame. – JacobMoore Jul 25 '19 at 10:28
  • 1) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 2) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 3) Provide ASCII art or a simple drawing of the *intended* .. – Andrew Thompson Jul 25 '19 at 13:52
  • .. layout of the GUI at minimum size, and if resizable, with more width and height - to show how the extra space should be used. 4) *`JLabel (pop_up)`* Also look at `JToolTip`. – Andrew Thompson Jul 25 '19 at 13:52
  • BTW `JOptionPane.showMessageDialog( null, "You haven't changed one or more of the text fields.", "Change a field!", JOptionPane.ERROR_MESSAGE);` – Andrew Thompson Jul 26 '19 at 08:47
  • 1
    @AndrewThompson Thanks :) I'll try that as well. It might look better than what I had in mind. – JacobMoore Jul 26 '19 at 09:45

0 Answers0