So, say that I have a really long line that I want to display in JLabel . How can i do this?
Currently, longer lines are appearing:

I need to resize the window to see the full text.
How can I make it so that where the text almost reaches the width of my JFrame ?
I'm not sure any code is needed here so you can answer it, but still:
my frame properties:
frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(450, 400)); frame.setLocation(new Point(400, 300)); frame.setLayout(new BorderLayout());
Label I want to change:
question = new JLabel("Question:"); question.setFont(new Font("Serif", Font.BOLD, 15)); question.setHorizontalAlignment(JLabel.CENTER);
EDIT: More Details:
I read the lines from the file and then show them. The line size is not fixed, so I donβt know where to put <br> in.
EDIT 2:
I ended up using JTextArea .
private JTextArea textAreaProperties(JTextArea textArea) { textArea.setEditable(false); textArea.setCursor(null); textArea.setOpaque(false); textArea.setFocusable(false); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); return textArea; }
java swing jpanel jlabel
user2027425
source share