Results 1 to 11 of 11

Thread: Extend Jscroll

  1. #1
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default Extend Jscroll

    I tried to inherit the Jcroll
    Java Code:
    package IV_FORM;
    
    import javax.swing.JScrollBar;
    
    public class Extended_scroll extends JScrollBar{
        
        public Extended_scroll(){
            
            
        }
    
    
    }
    And i want in my new Extended_scroll add then press the one of the 2 buttons(rigth or left) the value if Jtext increase by 1 or reduce by one.What method i should to rewrite?

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

    Default

    I don't think that there's enough information here to know how to help you. Please tell the details, including why you even want to extend JScrollBar.

  3. #3
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    I just want to reach 2 things...
    1.Get some experience with inheriting classes such Jscroll :)
    2.And at all i want using the buttons on a scroll for increase or reduce (differ from the button) the values in Jspinner.

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

    Default

    So you want to use inheritance to change a scrollbar into doing something that it was never intended to do? Good luck with that one as it will be very difficult to do, and not a wise thing to do either. But if you still feel a strong desire to tilt at this windmill, then I suggest you study the API for JScrollBar and its model the BoundedRangeModel, and then I suggest you delve a bit into the source code for both of these classes as well as the DefaultBoundedRangeModel class (you have already downloaded this zip file with the JDK. I think it's called src.zip).

    If I were your teacher though, I would suggest abandoning this quixotic quest and instead learn inheritance by doing something a bit more reasonable, such as playing with JTables and extending the different TableModels that are out there, but YMMV.

    Much luck.

  5. #5
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Thanks for your answer :) . I will tru to reach this aim just to pu only 2 jButtons on my From :) ..Anyway, thanks for your help! i will drop this stupid idea ..But i do not understand why it is so difficult to add a possible to increase values in some other components like textbox?

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

    Default

    Quote Originally Posted by cowboy View Post
    But i do not understand why it is so difficult to add a possible to increase values in some other components like textbox?
    You mean JTextField? Regardless, this goal should be much easier to attain than your first request. If you run into difficulties, please come on back with your code and let's see what we can do.

    Edit: another option is to change the appearances of a JSpinner.

    Good luck!
    Last edited by Fubarable; 12-13-2009 at 05:46 PM.

  7. #7
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Yes! I just want to change values in some exist component on my form(JSpinner date model). But i do not know how to rewrite or add method that edit the jSpinners buttons behavior. Tell what method i should to rewrite for this ?

    Nevertheless,From Russia with Love :) ?

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

  9. #9
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    "JScroll" is not a component. (Are you talking about a JScrollPane or JScrollBar?)

    "textbox" is not a component. (Are you talking about a JTextField, JTextArea or JTextPane?)

    English may not be your first language buy there is no reason for NOT using the proper Java terms when talking about components so we can better understand your question.

    But i do not understand why it is so difficult to add a possible to increase values in some other components like textbox?
    I don't understand what you are suggesting here. Do you mean to want to "increase", 'a' to 'b' to 'c'?

    Please give a better example for better help.

  10. #10
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    This is a prinscreen of my project


    Then i press the button number 3 - values(date) in jSpinner1 changing one day more or one day less. And i want to use a Extended jScroll bar for change a hour!! values in jSpinner1. One touch on rigth button(2)-the hour on jSppiner became more.One touch on left button(1) of ScrollBar- the hour became less.

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

    Default

    A JSpinner can scroll on the year, day, month, or hour, or whatever, depending on where the cursor is. For instance, in this code here, you can advance the year, month, day, hour, or minute if the cursor is in that portion of the text:

    Java Code:
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;
    
    import javax.swing.*;
    
    public class DateSpinner {
    
       private static void createAndShowUI() {
          final Calendar calendar = new GregorianCalendar();
          
          // code below from Sun tutorial:
          // http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html
          Date initDate = calendar.getTime();
          calendar.add(Calendar.YEAR, -100);
          Date earliestDate = calendar.getTime();
          calendar.add(Calendar.YEAR, 200);
          Date latestDate = calendar.getTime();
          final SpinnerDateModel model = new SpinnerDateModel(initDate,
                                       earliestDate,
                                       latestDate,
                                       Calendar.YEAR);
          
          JSpinner spinner = new JSpinner(model);
          spinner.setEditor(new JSpinner.DateEditor(spinner, "yyyy.MMMMM.dd   hh:mm aa"));
    
          
          JPanel panel = new JPanel();
          panel.add(spinner);
          JFrame frame = new JFrame("DateSpinner");
          frame.getContentPane().add(panel);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }

Similar Threads

  1. Trying to extend class
    By ribbs2521 in forum New To Java
    Replies: 4
    Last Post: 10-29-2009, 07:28 PM
  2. How can I extend java.net.URI - why is it final?
    By johann_p in forum Advanced Java
    Replies: 1
    Last Post: 08-21-2009, 06:31 AM
  3. extend a button
    By Omarero in forum New To Java
    Replies: 0
    Last Post: 03-25-2009, 07:57 PM
  4. using J-classes or extend them ?
    By itaipee in forum AWT / Swing
    Replies: 1
    Last Post: 01-01-2009, 08:58 PM
  5. How to extend Messages Component
    By Jothi in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 05-20-2008, 09:50 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
  •