I want to draw graphicaly a square wave pulse train. This will work by users pressing on a canvas and the x coord generating a toggle point (high or low switch). Can anyone reccomend any java packages or external packages where this could be done or will I have to create my own package.
As a continuation, I would like to have a stationary pulse train that is around 200 * 30000 pixels long. Obviously I will need some sort of scrollbar in my graphics window to move beetween different points in the pulse train, but I am not sure how to go about this as it seems complex.
An idea was to only display the coords in the range offset determined by the scrollbar cursor position.
Any pointers to code that does this sort of thing?
how long did it take you to write that I didn't notice will need some sort of scrollbar in my graphics window Setting the preferred size of the component will take care of this. The parent JScrollPane asks for this Dimension when it is ready to set its scrollbars for display of its child component/view. display the coords in the range offset determined by the scrollbar cursor position Java clips the graphics context so our custom graphics are drawn only on the visible area.
I want to add more functionality to this, however when I want to set the content pane to have a flowlayout, it distorts things and the scroll bars disappear completely
FlowLayout is not a good choice for this. You can add components to the other sections of the JFrames default BorderLayout (north, west, east and south). Or you can assemble the graphic component (StandingWave) with other components and add them to the center section of the layout. Making friends with the layout managers takes some patience and practice. For more information there is Lesson: Laying Out Components Within a Container with links to some useful pages: 1 — A Visual Guide to Layout Managers 2 — Using Layout Managers 3 — How to... I added the graphic component to the center of the BorderLayout which expands it in both directions to fill the available space. Therefore I did not have to provide any size hints beyond the width (30000) which I set in the preferredSize. These little tricks come with practice and experimentation. A Flowlayout will show the component at its preferredSize which is the default height (10, I didn't change this) and the width of 30000. Another peculiarity of FlowLayout is that it does not calculate the size of components that are not visible; it reports only the size of the visible (portion of the) components in the gui. So the JScrollPane doesn't get the correct information it needs to properly display the component.
In the following code I only have one Jscrollpane appearing Look at the second paragraph in the discussion section of the BorderLayout api: using no constraint defaults to the center section (BorderLayout.CENTER = "Center"). The first JScrollPane is removed from the center section and the second one is added.