Graphical Representation of Text Input - Multiple JPanels in a JScrollPane
Have put in a lot of hours trying to get this work including a lot of searching for the solution on the Internet but have been unable to find a solution....today was my deadline..... oh well!
I have a Java program that generates graphics on a JPanel for every line of input data from a text file. I am running into two problems. 1) The graphics are not fully displayed because they overlay each other with this BoxLayout that I am using.... 2) I cannot get the ScrollBar on the JScrollPane to work - it shows up, but the slider thingy doesn't appear. Wish I could show you a picture of this somehow. (SEE ATTACHMENT)
Once again the intention is to produce one JPanel (or whatever other class I would need) of graphics for every data input record from a text file. This is so they can just grab the scroll bar and review each one of the graphical representations from the first to the last. Therefore, I should be able to make this Frame, or ScrollPane or whatever as big as is needed in order to display all these graphics. And the trick is to be able to append one JPanel after another and then resize accordingly. This isn't happening with BoxLayout because it only gives me one screen size full of scrunched up JPanels. Also, I have no idea why my scrollbar does not show up correctly.....
Code: Although this isn't the exact code...(that would be too lengthy) it will gave you an idea of what I am trying to do.... I have everything in basically two classes... (time constraints)
Here is the whole first class since it is rather short.......and shows
what I am trying to do. Please ignore class names. They are meaningless.
public class Java2DExampleCustom extends JPanel implements Scrollable {
String shape;
BasicStroke stroke = new BasicStroke(1.0f);
BasicStroke wideStroke = new BasicStroke(4.0f);
String s1,s2,s3,s4,s5;
String c1,c2,c3,c4,c5;
String p1,p2,p3,p4,p5;
private int maxUnitIncrement = 1;
/**
* Our Java2DExample constructor sets the frame's size, adds the
* visual components, and then makes them visible to the user.
* It uses an adapter class to deal with the user closing
* the frame.
**/
public Java2DExampleCustom(String token1, String token2, String token3) {
ETC, ETC , ETC
public boolean getScrollableTracksViewportWidth() {
return false;
}
public boolean getScrollableTracksViewportHeight() {
return false;
}
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
int currentPosition = 0;
if (orientation == SwingConstants.HORIZONTAL)
currentPosition = visibleRect.x;
else
currentPosition = visibleRect.y;
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
if (orientation == SwingConstants.HORIZONTAL)
return visibleRect.width - maxUnitIncrement;
else
return visibleRect.height - maxUnitIncrement;
}
/**
* The paint method provides the real magic. Here we
* cast the Graphics object to Graphics2D to illustrate
* that we may use the same old graphics capabilities with
* Graphics2D that we are used to using with Graphics.
**/
public void paint(Graphics g) {
Bookmarks