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]
# 1

So what is your problem then?

_helloWorld_a at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 2

> So what is your problem then?

besides that you're using netbeans, that is.

petes1234a at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 3

Also, the chances are you don't need any event handling code on your ScrollPane. Should you not be adding the events to your viewport view? (the thing that lives in the ScrollPane, the JEditorPane or whatever you are using).

_helloWorld_a at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 4

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.

morganista at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 5

Unfortunately your question is very IDE dependent. Many (most?) of us don't use netbeans but rather would prefer to hand-code our own swing routines. I'm not going to debate on which is better, but only state this to note that this makes the number of folks with the specific knowledge to answer your question small indeed. Hopefully someone here will be able to answer you, but while waiting, you may do well to find a netbeans-specific forum and ask this same question there.

Best of luck

/Pete

petes1234a at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 6

Thanks again for getting back to me so quickly. I have to admit that I that I feel a bit stupid because I know that using scrollbars is very simple (did I seem a bit stupid?). Now that I have explained that I don't have a clue about what I am doing and why I hope that you can understand why I have so much difficulty. Can you suggest any netbeans specific sites or forums that I could look at. I know that I could do a search easily but you obviously know what your talking about and have experience so I thought that it might be a good idea to ask you about any good sites.

Can I ask where you are all from I am in the UK I am assuming that you are American. In the UK the books on java aren't the most up to date volumes. I had a look on amazon US and the books were a lot more up to date and more specific than in the UK I know that I could buy the american books but it would take ages for the shipping.

morganista at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 7

> 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));

}

}

_helloWorld_a at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 8

The core of java doesn't change as much as you think. I have been learning java with some out of date books for the core info and websites for the most recent changes.

petes1234a at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...
# 9

Thank you for all of your help I have actually figured it out now so I don't need any more assistance. Can I give special thanks to petes1234 and helloworld who made a great deal of effort to help me.

Thank you very much.

morganista at 2007-7-29 14:30:48 > top of Java-index,Java Essentials,New To Java...