Results 1 to 10 of 10
Thread: Help with sliders in java
- 07-31-2012, 01:30 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 9
- Rep Power
- 0
Help with sliders in java
i have three sliders s1,s2 and s3. s3 is non-editable where as s1 and s2 are editable. s1 and s2 have min and max of 0 and 200 whereas s3 has a min and max of 0 and 50.value of s3 by default is 50. what i want is when i increase s1 or s2 by 1 or more, s3 should go down by same value and if s3 reaches 0 s1 or s2 cannot be futher increased. same with decrease.when i decrease s1 or s2 by 1 or more, s3 should go up by same value and if s3 reaches 50 s1 or s2 cannot be futher decreased.
- 07-31-2012, 02:21 PM #2
Re: Help with sliders in java
Do you have code you are working on to do this? Please post a small, simple program that compiles and executes and shows the problem.
If you don't understand my response, don't ignore it, ask a question.
- 07-31-2012, 02:27 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 9
- Rep Power
- 0
Re: Help with sliders in java
this is the code. what i want is if i increase s1 or s2 , s3 should go down by same value and if s3==0 then s1 or s2 cannot be futher increasedJava Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * delete.java * * Created on Jul 31, 2012, 5:53:38 PM */ /** * * @author Owner */ public class delete extends javax.swing.JFrame { /** Creates new form delete */ public delete() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { s1 = new javax.swing.JSlider(); s2 = new javax.swing.JSlider(); jSlider1 = new javax.swing.JSlider(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); s1.setMaximum(200); s1.setValue(0); s2.setMaximum(200); s2.setValue(0); jSlider1.setMaximum(50); jSlider1.setEnabled(false); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(40, 40, 40) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(s2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(s1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(160, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(57, 57, 57) .addComponent(s1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(28, 28, 28) .addComponent(s2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(43, 43, 43) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(103, Short.MAX_VALUE)) ); pack(); }// </editor-fold> /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new delete().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JSlider jSlider1; private javax.swing.JSlider s1; private javax.swing.JSlider s2; // End of variables declaration }
- 07-31-2012, 02:38 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Help with sliders in java
A bit of 101 math would show that the range of s1 and s2 is also [0, 50].
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-31-2012, 04:05 PM #5
Re: Help with sliders in java
The code does not have any listeners to react to changes in the sliders's values. You'll need to add them to do what you want.
If you don't understand my response, don't ignore it, ask a question.
- 07-31-2012, 05:42 PM #6
Member
- Join Date
- Jul 2012
- Posts
- 9
- Rep Power
- 0
- 07-31-2012, 05:55 PM #7
Re: Help with sliders in java
Read the API doc for the JSlider class to see how to use listeners with it.
Add listeners to the sliders in your code and to see data is available when they are called, print out the event object that is passed to the listener. Also look at the API doc for the event object passed to the listener to see what data you can get from the object. Once you see what data is available and how to get it, you can then start working on the logic to solve your problem.If you don't understand my response, don't ignore it, ask a question.
- 07-31-2012, 05:57 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Help with sliders in java
And when you know what sort of listener, here's the tutorial for how to use them.
Please do not ask for code as refusal often offends.
- 07-31-2012, 06:27 PM #9
Member
- Join Date
- Jul 2012
- Posts
- 9
- Rep Power
- 0
Re: Help with sliders in java
i'm a noob so can u write me a sample program as an example. plz ?
- 07-31-2012, 06:33 PM #10
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Similar Threads
-
How to use SWT Sliders
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:06 PM -
How to use vertical and horizontal sliders in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:06 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks