• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JScrollPanel does not appear

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
We can walk to school together. And we can both read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic