• Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollPane and FlowLayout  RSS feed

 
Nick Lebian
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Is there a posibility to use the FlowLayout and JScrollPane in one JFrame/JApplet? My Problem is that I hava a text splitted in many JLabels and want to show this text in an Applet with the help of the FlowLayout. But I need a vertical srollbar, if the text is too long. But when I add the JPanel with the FlowLayout to the Applet, the hole text is shown in one line without a line break. Here a part of the code:
...
JPanel MyJPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,4,4));
...
Iterator it=labelList.iterator();
while (it.hasNext())
MyJPanel.add((Component)it.next());
...
JScrollPane scrollpaneExercise = new JScrollPane(MyJPanel);
getContentPane().add(BorderLayout.CENTER, scrollpaneExercise);
...
Nick
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are expecting FlowLayout to insert line breaks into your series of JLabels if they flow over the JApplet/JFrame side. An't gonna happen. FlowLayout goes from left to right (or from right to left in appropriate locales) in a single row.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try GridLayout, BoxLayout or GridBagLayout
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!