I have had trouble with scrollbars using netbeans 5.5.1
I have had trouble getting a vertical and horizontal scrollbar working in my GUI. I am new to programming but I have books but I find them difficult to follow because they follow the old netbeans GUI models that requires all of the code to be written for example the scrollbar has to be created and then the parameters have to be set. However with the 5.5.1 the scrollbar has already been created and the parameters of the maximum the minimum and the event have already been set.
Therefore when you follow the books they explain the whole process rather than the last part which is all that is needed. I have selected the scrollbar and then pressed the right mouse button to get the menu up where I selected Events and then Adjustments, which then displayed the following script,
" private void jScrollBar1AdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
// TODO add your handling code here:"
I know that I have to delete the //TODO add your handling code here and then insert the event handling code. I have tried to put in a lot of different event handler codes to try to get it to work but I have had no luck. Can anybody help. I have asked a few people but they have had trouble with it too.
[1239 byte] By [
morganista] at [2007-11-27 11:18:25]

Hi thank you for getting back to me so quickly. And I do appreciate that what I have asked is very basic. The problem that I have is that I am a macro economist and have to write a computer program that enables people to do their tax returns in a simpler way than previously done. Therefore I have never done anything on computers before other than general office work. I have actually written the all of the rest of the program and it works it is fairly complicated, as it uses a lot of conditional logic and some conplicated accounting principles.
Anyway I have had to give my self a crash course in java and have only been writing for three weeks, most of which I have been concentrating on the conditional logic rather than the general swing tools that an professional programmer would need. Anyway like I said I have already written the rest of the program and only have to get the scrollbars working so that all of the GUI can be accessed.
I understand that a lot of people don't ask direct questions when they make a post so I will make a direct request to clarify what could be useful to me in my situation.
Can anybody provide me with a scrollbar script that they have used in netbeans 5.5.1 so that I can see how it differs from the script that I have in my books and therefore I will be able to work out where I am going wrong. I am currently entering codes from books and websites but I still can get my scrollbars functioning. I have tried rearranging the scripts to try to get them to work but I haven't got any where.
Please can somebody provide me with a scirpt example. I would really appreciate it.
> Please can somebody provide me with a scirpt example.
> I would really appreciate it.
This was not made in Netbeans but it shows you how to use scrollpanes with a viewportview and listeners.
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
public class SwingExample {
public static void main(String[] args) {
JFrame frame = new JFrame("Test");
//Create scrollpane
JScrollPane scrollpane = new JScrollPane();
//Create textpane to embed in Scrollpane
JTextPane textPane = new JTextPane();
//Add listener to textpane to listen for a KeyEvent
textPane.addKeyListener(new KeyListener() {
//unimplemented methods, not reuqired for example
public void keyPressed(KeyEvent arg0) {}
public void keyReleased(KeyEvent arg0) {}
//Implemented method - prints current key typed.
public void keyTyped(KeyEvent arg0) {
char myChar = arg0.getKeyChar();
System.out.println("You Typed: "+myChar);
}
});
//Add textpane to scrollpane
scrollpane.setViewportView(textPane);
//add scrollpane to frame
frame.add(scrollpane);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(new Dimension(400,400));
}
}