Note that there are some explanatory texts on larger screens.

plurals
  1. POReading text from file and putting it to the JLabel
    primarykey
    data
    text
    <p>I want to change my JLabel when I click a JButton. It sounds simple but can't really find a good piece of code. Here is part of my code:</p> <pre><code> final JButton continueGame = new JButton(); continueGame.setPreferredSize(new Dimension(1000, 30)); continueGame.setLocation(95, 45); continueGame.setText("&lt;html&gt;Continue&lt;/html&gt;"); continueGame.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent ev) { panel.remove(continueGame); SwingUtilities.updateComponentTreeUI(frameKontrastGame); if(RandomNrJeden &lt;= 50) { JOptionPane.showMessageDialog(frameKontrastGame, "Eggs are not supposed to be green."); frameKontrastGame.setVisible(false); JFrame frameScenario2 = new JFrame(); frameScenario2.setTitle("Scenario2"); frameScenario2.setSize(1000,700); frameScenario2.setLocationRelativeTo(null); frameScenario2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panelScenario = new JPanel (); panel.setLayout(new GridLayout(2, 1)); final JLabel tekst = new JLabel (); tekst.setText("&lt;html&gt;Część dialogu numer 1&lt;/html&gt;"); //JTextField dialog = new JTextField(20); //dialog.setText("&lt;html&gt;Eggs are not supposed to be green.&lt;/html&gt;"); JButton OdpPierwsza = new JButton (); OdpPierwsza.setText("&lt;html&gt;Opowiedź pierwsza&lt;/html&gt;"); OdpPierwsza.addActionListener (new ActionListener(){ @Override public void actionPerformed(ActionEvent ev) { tekst.setText("&lt;html&gt;HERE I NEED A TEXT FROM FILE dialog.txt&lt;/html&gt;"); } }); //panelScenario.add(dialog); panelScenario.add(tekst); panelScenario.add(OdpPierwsza); frameScenario2.getContentPane().add(panelScenario); frameScenario2.setVisible(true); } </code></pre> <p>(If the brackets are wrong that's because its not the whole code.)</p> <p>So:</p> <ul> <li>Where is the "HERE I NEED A TEXT FROM FILE dialog.txt" I need some kind of reader. The best one will be the one which reads text line by line. I just cant find how to write it.</li> <li>I need to add the <code>JLabel</code> to the <code>JPanel</code>.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload