• 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

JScrollPanel does not appear

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've a little problem with the JScrollPanel. It does not appear. I tried a lot of configurations and possible solutions to see them, but nothing works. So, here is a little code fragment which describes my problem:


Thanks for help ...
Fredwurst
(edited by Cindy to get the font big enough to READ)

[This message has been edited by Cindy Glass (edited September 03, 2001).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fredwurst,
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at "JavaRanch Naming Policy" . We require names to have at least two words (not just letters), separated by a space, and strongly recommend that you use your full real name. We want to get to know you as a Professional. Please choose a new name which meets the requirements and re-register.
Cindy
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the short name ... i didn't read the JavaRanch Naming Policy carefully. I reregistered now with my full name ...
Fredwurst
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setting the scrollbar policy when you create your JScrollPane to always on.
 
Hineck Fredwurst
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out. Now it works. Have a look on the following code:
<CODE>
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class TestFrame
{
public JButton button;
public JFrame jFrame = new JFrame();
public JScrollPane scrollPane;
public JSplitPane jSplitpane;
public PaintPanel panel;
public static void main(String[] args)
{
TestFrame frame = new TestFrame();
}
public TestFrame()
{
jFrame.setSize(300,300);
jFrame.setLocation(300,300);
panel = new PaintPanel();
panel.setBackground(Color.black);
panel.setSize(1000,1000);
scrollPane = new JScrollPane(panel);
panel.setPreferredSize(new Dimension(1000,1000));
button = new JButton();
button.setText("Step");
jSplitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,button,scrollPane);
jSplitpane.setContinuousLayout(true);
jFrame.getContentPane().add(jSplitpane);
jFrame.setVisible(true);
button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button_actionPerformed(e);
}
});
}
void button_actionPerformed(ActionEvent e) {
this.panel.repaint();
}
}
class PaintPanel extends JPanel
{
private int x1 = 0;
private int x2 = 0;
private int y1 = 0;
private int y2 = 0;
private Random r = new Random();
private ArrayList arrayList = new ArrayList();
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.white);
paintLine(g);
}
protected void paintLine(Graphics g)
{
ArrayList v = new ArrayList();
v = createNewData();
arrayList.add(v);
for (int n=0;n<arrayList.size()-1;n++)>
{
v = (ArrayList) arrayList.get(n);
x1 = ((Integer) v.get(0)).intValue();
y1 = ((Integer) v.get(1)).intValue();
x2 = ((Integer) v.get(2)).intValue();
y2 = ((Integer) v.get(3)).intValue();
g.drawLine(x1,y1,x2,y2);
}
}
public ArrayList createNewData()
{
ArrayList v = new ArrayList();
for (int n=0;n<4;n++){
Integer a = new Integer((int)(r.nextInt(1000)));
v.add(a);
}
return v;
}
}
</CODE>
Thanks,
Fredwurst
 
Evil is afoot. But this tiny ad is just an 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!