I have a JLabel which has a lot of text on it. Is there a way to make the JLabel have a max width so that it will wrap the text to make it not exceed this width?
Tha
wrapping works but not in all cases. If the parent container uses FlowLayout then it'll not work. Therefore I set it to BoxLayout. Look at this code snippet:
javax.swing.JPanel pRefundNote = new javax.swing.JPanel();
javax.swing.JLabel lbNote = new javax.swing.JLabel();
pRefundNote.setAlignmentX(0.0F);
pRefundNote.setMaximumSize(new java.awt.Dimension(32767, 33));
pRefundNote.setLayout(new javax.swing.BoxLayout(pRefundNote, javax.swing.BoxLayout.X_AXIS));
lbNote.setText("Select items using Shift or Ctrl and Up/Down keys or Mouse");
lbNote.setVerticalAlignment(javax.swing.SwingConstants.TOP);
lbNote.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
pRefundNote.add(lbNote);
Don't add
because it'll break your text even if you enlarge your parent frame and pRefundNote container.