Results 1 to 4 of 4
  1. #1
    Charlie161 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default JSlider change JPanel[][] rows and columns

    Hello
    I'm new with Java, learning it in college.
    I'm trying to make a GUI with a "four in a row" board. The user should be able to change the number of rows and columns Instantly (without pressing a button) using a JSlider.
    I've got the board. How do I make the a JSlider.getValue() working instantly?

    Java Code:
    private void maakPnlCenter() {
            waardeKolommen = slAantalKolommen.getValue();
            waardeRijen = slAantalRijen.getValue();
    
            JPanel pnlCenter = new JPanel();
            pnlCenter.setLayout(new GridLayout(waardeRijen, waardeKolommen));
            JPanel vakken[][] = new JPanel[waardeRijen][waardeKolommen];
    
    
            for (int i = 0; i < waardeRijen; i++) {
                for (int j = 0; j < waardeKolommen; j++) {
                    vakken[i][j] = new JPanel();
                    vakken[i][j].setBorder(new LineBorder(Color.black));
                    vakken[i][j].setPreferredSize(new Dimension(80, 80));
                    pnlCenter.add(vakken[i][j]);
    
    
                }
            }
    
            this.add(pnlCenter, BorderLayout.CENTER);
    
    
    
        }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Please have a look at the JSlider tutorial here: Sliders. It will tell you how to add a listener to the slider and respond to its events.

  3. #3
    Charlie161 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks, I already tried that tutorial. So I made a Change Listener. How do I make my pnlCenter to change? Does it have to redraw completely? I read something with a rePaint() function. But pnlCenter.rePaint() doesn't seem to werk.

  4. #4
    Charlie161 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    I found the revalidate() method, so it's working fine now :)

Similar Threads

  1. How to write database queries in Jtable rows and columns?
    By Vignesh Karthick in forum AWT / Swing
    Replies: 1
    Last Post: 02-02-2011, 03:55 PM
  2. How to create 3 columns and 2 rows tablelayout in Java
    By newbiejava in forum New To Java
    Replies: 5
    Last Post: 07-17-2010, 03:24 AM
  3. Need a loop for rows and columns
    By Ceasar in forum New To Java
    Replies: 4
    Last Post: 10-09-2009, 03:03 PM
  4. Counting Rows and Columns from Excel Sheet
    By Anish in forum Advanced Java
    Replies: 3
    Last Post: 12-24-2008, 06:56 AM
  5. Two diM aRRay and add rows and columns....
    By filly444 in forum New To Java
    Replies: 2
    Last Post: 08-30-2008, 05:24 PM

Posting Permissions

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