• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

JScrollPane and FlowLayout

 
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
 
Bartender
Posts: 9567
12
Mac OS X Linux 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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try GridLayout, BoxLayout or GridBagLayout
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!