Results 1 to 3 of 3
  1. #1
    GeorgyBoy is offline Member
    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Default JscrollBar not working

    Hi, i'm new to Java and i have this exercise to make.
    The purpose is to enter a number in the inputfield and the code has to process the input in order to multiply it incrementaly 100 times (for loop)and finally displaying a list tha tlooks like :
    0x10 = 0
    1x10 = 10
    2x10 = 20
    3x10 = 30 ect...
    So we need a scrollBar since the frame is to small to containt the entire output.
    Please copy and paste my code and help me fix this.


    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;

    class Rekenen extends JFrame {
    private JTextField inputField = new JTextField(4);
    JScrollPane spane;
    private JLabel output = new JLabel();
    static int result;

    public static void main(String[] args) {
    Rekenen window = new Rekenen();
    window.setSize(300, 300);
    window.setVisible(true);
    }

    public Rekenen() {
    // Create button and add action listener.

    JButton berekenButton = new JButton("Compute");
    spane = new JScrollPane();
    berekenButton.addActionListener(new Listener());

    // Set layout and add components.
    JPanel content = new JPanel();
    content.setLayout(new FlowLayout());
    content.add(berekenButton);
    content.add(inputField);
    content.add(output);
    // Set the window characteristics.

    content.setBackground(Color.BLACK);
    setContentPane(content);
    setTitle("RekenApp");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    spane.setLocation(0, 35);
    setLocationRelativeTo(null); // Center window.
    }
    private class Listener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    int cijfer = (int) Double.parseDouble(inputField.getText());

    int berekening = (int) computeCijfer(cijfer);

    output.setText(result);

    }
    }

    public static double computeCijfer(int cijfer) {

    for (int i = 0; i < 100; i++) {
    int result = cijfer * i;

    }

    return result;

    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: JscrollBar not working

    Please go through Guide For New Members and BB Code List - Java Programming Forum and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: JscrollBar not working

    Read the API for JScrollPane and follow the link to the Swing tutorial on How to Use Scroll Panes. Just constructing one and setting its location doesn't do anything to the components that you have actually added to the GUI hierarchy.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JScrollbar not working
    By Tastosis in forum New To Java
    Replies: 7
    Last Post: 03-22-2011, 07:22 AM
  2. paint with JScrollBar
    By shakeel in forum Java 2D
    Replies: 5
    Last Post: 12-23-2010, 05:35 PM
  3. Problem with JScrollBar
    By Arthur in forum AWT / Swing
    Replies: 3
    Last Post: 02-19-2010, 03:59 AM
  4. A problem with JScrollBar and the Jbutton
    By cowboy in forum New To Java
    Replies: 5
    Last Post: 12-19-2009, 10:17 PM
  5. JScrollBar
    By solomon_13000 in forum AWT / Swing
    Replies: 1
    Last Post: 07-01-2009, 08:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •