Results 1 to 4 of 4
  1. #1
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Exclamation Problem with JScrollPane and VK_TAB

    I am facing a problem with my JScrollpane and TAB key.
    In my GUI after pressing TAB key the Scrollpane should be scroll and the TextField holding the control should be focused. But I can't do that.
    I will be very thankful if anybody help me.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    To get better help sooner, post a SSCCE* that demonstrates your problem.
    * SSCCE : Java Glossary

    And don't forget to use the code tags.

    db

  3. #3
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    My code is as follows-
    I want to do something that the scrollpane is forced to scroll to the textfield that currently holding the controle after pressing the TAB key.....................

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    
    public class trans_gift
    	 {
    		public static void main(String s[])
    	 	   {
    			gift gi=new gift();
    
    		   }
    	}
    
    class gift extends JFrame implements ActionListener,FocusListener
    
    	{
    
              int id_ref=1;
              BoundedRangeModel rangeMode;
    
              JPanel a=new JPanel();
    
              String color="";
              String print_type="";
              String noi="";
              String print_charge="";
              
              JScrollPane abc=new JScrollPane(a,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    
              JLabel lblorder_no=new JLabel("Job No.");
    	   JTextField txtorder_no=new JTextField(20);
    
    	   JLabel lblorder_item=new JLabel("Nature of Job");
    	   JTextField cmborder_item=new JTextField();
    
               JLabel lbljob_to_use=new JLabel("Job Size");
    	   JTextField cmbjob_to_use=new JTextField(20);
    
               JLabel lblno_of_copies=new JLabel("No of Coupons");
    	   JTextField txtno_of_copies=new JTextField(20);
    
               JLabel lblwastage=new JLabel("wastage");
    	   JComboBox cmbwastage=new JComboBox();
    
               JLabel lbltotal_no_of_copies=new JLabel("Total No. of Copies");
    	   JTextField txttotal_no_of_copies=new JTextField(20);
    
               JLabel lblpaper_to_use=new JLabel("Paper Size");
    	   JLabel lblpaper_type=new JLabel("Paper Type");
               JComboBox cmbpaper_type1=new JComboBox();
    
               JComboBox cmbpaper_type2=new JComboBox();
               JComboBox cmbpaper_type3=new JComboBox();
    
               JLabel lblgsm=new JLabel("GSM of Paper");
    	   JComboBox cmbgsm=new JComboBox();
    
               JLabel lblno_of_full_sheets_required=new JLabel("No of Full Sheets Required");
    	   JTextField txtno_of_full_sheets_required=new JTextField(20);
    
    	   JLabel lblprice_per_full_sheet=new JLabel("Price Per Full Sheet");
    	   JTextField txtprice_per_full_sheet=new JTextField(20);
    
               JLabel lbltotal_cost_of_paper=new JLabel("Total Cost of Paper");
    	   JTextField txttotal_cost_of_paper=new JTextField(20);
    
               JLabel lblleaves=new JLabel("Leaves Per Book");
    	   JTextField txtleaves=new JTextField(20);
    
               JLabel lblprinting_sides=new JLabel("Printing_Sides");
               JTextField txtprinting_sides=new JTextField(20);
               
    
               JLabel lblcolor_specification=new JLabel("Color Specification");
               JComboBox cmbcolor_specification=new JComboBox();
               
               JLabel lblprinting_type=new JLabel("Printing Type");
    	   JComboBox cmbprinting_type=new JComboBox();
    
               JLabel lblno_of_impressions=new JLabel("No of Impressions");
    	   JTextField txtno_of_impressions=new JTextField(20);
    
               JLabel lblprinting_charge=new JLabel("Printing Charge");
    	   JTextField txtprinting_charge=new JTextField(20);
    
               JLabel lbltotal_printing_charge=new JLabel("Total Printing Charge");
    	   JTextField txttotal_printing_charge=new JTextField(20);
               JLabel lbldesign_charge=new JLabel("Design Charge");
    	   JTextField txtdesign_charge=new JTextField(20);
    
               JLabel lblplate_charge=new JLabel("Plate Charge");
    	   JTextField txtplate_charge=new JTextField(20);
    
               JLabel lblBinding_charge=new JLabel("Binding Charge");
    	   JTextField txtbinding_charge=new JTextField(20);
    
               JLabel lblnumbering_charge=new JLabel("Numbering Charge");
    	   JTextField txtnumbering_charge=new JTextField(20);
    
               JLabel lblperforation_charge=new JLabel("Perforation Charge");
    	   JTextField txtperforation_charge=new JTextField(20);
    
               JLabel lbltotal_cost=new JLabel("Total Cost");
    	   JTextField txttotal_cost=new JTextField(20);
    
               JButton btnokp=new JButton("OK");
    
               JButton btnok=new JButton("OK");
               JButton btncancel=new JButton("Cancel");
    
    
    
    
    
               
    
               gift()
                   {
                            super("Order Form");
        	        	this.getContentPane().setLayout(null);
    			a.setLayout(null);
                            
    			
                            Dimension screenSize=this.getToolkit().getScreenSize();
    			this.setSize(screenSize);
     	        	
    			abc.setSize(screenSize.width-9,screenSize.height-9);
    			a.setPreferredSize(new Dimension(200,2500));
                            this.setResizable(false);
    
                            a.add(lblorder_no);
    			lblorder_no.setBounds(10,20,250,25);
    
    			a.add(txtorder_no);
    			txtorder_no.setBounds(260,20,400,25);
    
    			a.add(lblorder_item);
    			lblorder_item.setBounds(10,55,250,25);
    
                            a.add(lbljob_to_use);
    			lbljob_to_use.setBounds(10,90,250,25);
    
                            a.add(cmbjob_to_use);
    			cmbjob_to_use.setBounds(260,90,400,25);
                            
                            cmbjob_to_use.setEditable(false);
    
    			a.add(cmborder_item);
    			cmborder_item.setBounds(260,55,400,25);
                            
                            cmborder_item.setEditable(false);
    
    			a.add(lblno_of_copies);
    			lblno_of_copies.setBounds(10,125,250,25);
    
    			a.add(txtno_of_copies);
    			txtno_of_copies.setBounds(260,125,400,25);
    
                            a.add(lblwastage);
    			lblwastage.setBounds(10,160,250,25);
                            
    
    
    			a.add(cmbwastage);
    			cmbwastage.setBounds(260,160,400,25);
                            cmbwastage.setEditable(rootPaneCheckingEnabled);
                            cmbwastage.addItem("25");
                            cmbwastage.addItem("50");
                            cmbwastage.addItem("75");
                            cmbwastage.addItem("100");
    
    
    			a.add(lbltotal_no_of_copies);
    			lbltotal_no_of_copies.setBounds(10,195,250,25);
    
    			a.add(txttotal_no_of_copies);
    			txttotal_no_of_copies.setBounds(260,195,400,25);
                            txttotal_no_of_copies.addFocusListener(this);
    
                            a.add(lblpaper_to_use);
    			lblpaper_to_use.setBounds(10,230,250,25);
    
    			a.add(cmbpaper_type1);
    			cmbpaper_type1.setBounds(260,230,400,25);
                            cmbpaper_type1.setEditable(false);
                            cmbpaper_type1.addFocusListener(this);
    
    			a.add(lblpaper_type);
    			lblpaper_type.setBounds(10,265,250,25);
    			txtdesign_charge.addFocusListener(this);
    			a.add(cmbpaper_type2);
    			cmbpaper_type2.setBounds(260,265,400,25);
                            cmbpaper_type2.addFocusListener(this);
    
                            cmbpaper_type2.addItem("coated");
                            cmbpaper_type2.addItem("Non-coated");
    
                            a.add(cmbpaper_type3);
    			cmbpaper_type3.setBounds(260,300,400,25);
    
    
    			a.add(lblgsm);
    			lblgsm.setBounds(10,335,250,25);
    
    			a.add(cmbgsm);
    			cmbgsm.setBounds(260,335,400,25);
                            cmbgsm.addFocusListener(this);
    
    			a.add(lblno_of_full_sheets_required);
    			lblno_of_full_sheets_required.setBounds(10,370,250,25);
    
    			a.add(txtno_of_full_sheets_required);
    			txtno_of_full_sheets_required.setBounds(260,370,400,25);
                            txtno_of_full_sheets_required.addFocusListener(this);
    
    			a.add(lblprice_per_full_sheet);
    			lblprice_per_full_sheet.setBounds(10,405,250,25);
    
    			a.add(txtprice_per_full_sheet);
    			txtprice_per_full_sheet.setBounds(260,405,400,25);
                            txtprice_per_full_sheet.addFocusListener(this);
    
    			a.add(lbltotal_cost_of_paper);
    			lbltotal_cost_of_paper.setBounds(10,440,250,25);
    
    			a.add(txttotal_cost_of_paper);
    			txttotal_cost_of_paper.setBounds(260,440,400,25);
                            txttotal_cost_of_paper.addFocusListener(this);
                            txttotal_cost_of_paper.setText("0");
    
                            a.add(lblleaves);
    			lblleaves.setBounds(10,475,250,25);
    
                            a.add(txtleaves);
    			txtleaves.setBounds(260,475,400,25);
    
                            a.add(lblprinting_sides);
    			lblprinting_sides.setBounds(10,510,250,25);
    
                            a.add(txtprinting_sides);
                            txtprinting_sides.setBounds(260,510,400,25);
                            txtprinting_sides.setEditable(false);
                            txtprinting_sides.setText("Front Side");
    
                            
    
                            a.add(lblcolor_specification);
    			lblcolor_specification.setBounds(10,545,250,25);
    
                            a.add(cmbcolor_specification);
                            cmbcolor_specification.setBounds(260,545,400,25);
                            cmbcolor_specification.addItem("Single Color");
                            cmbcolor_specification.addItem("Multi Color");
                            cmbcolor_specification.setSelectedItem("Multi Color");
    
    
                            
    
                            a.add(lblprinting_type);
    			lblprinting_type.setBounds(10,580,250,25);
    
                            a.add(cmbprinting_type);
                            cmbprinting_type.addItem("----------------------select--------------------");
    			cmbprinting_type.setBounds(260,580,400,25);
    
                            a.add(lblno_of_impressions);
    			lblno_of_impressions.setBounds(10,615,250,25);
    
    			a.add(txtno_of_impressions);
    			txtno_of_impressions.setBounds(260,615,400,25);
                            txtno_of_impressions.addFocusListener(this);
    
                            a.add(lblprinting_charge);
    			lblprinting_charge.setBounds(10,650,250,25);
    
    			a.add(txtprinting_charge);
    			txtprinting_charge.setBounds(260,650,300,25);
                            txtprinting_charge.addFocusListener(this);
                            txtprinting_charge.setEditable(false);
    
                            a.add(btnokp);
                            btnokp.setBounds(580,650,80,25);
                            btnokp.addActionListener(this);
    
                            a.add(lbltotal_printing_charge);
    			lbltotal_printing_charge.setBounds(10,685,250,25);
    
    			a.add(txttotal_printing_charge);
    			txttotal_printing_charge.setBounds(260,685,400,25);
                            txttotal_printing_charge.addFocusListener(this);
                            txttotal_printing_charge.setEditable(false);
                            txttotal_printing_charge.setText("0");
    
    
                            a.add(lbldesign_charge);
                            lbldesign_charge.setBounds(10,720,250,25);
    
                            a.add(txtdesign_charge);
                            txtdesign_charge.setBounds(260,720,400,25);
                            txtdesign_charge.setText("0");
                            txtdesign_charge.addFocusListener(this);
    
                            a.add(lblplate_charge);
                            lblplate_charge.setBounds(10,755,250,25);
    
                            a.add(txtplate_charge);
                            txtplate_charge.setBounds(260,755,400,25);
                            txtplate_charge.setText("0");
    
                            a.add(lblBinding_charge);
                            lblBinding_charge.setBounds(10,790,250,25);
    
                            a.add(txtbinding_charge);
                            txtbinding_charge.setBounds(260,790,400,25);
                            txtbinding_charge.setText("0");
                            a.add(lblnumbering_charge);
                            lblnumbering_charge.setBounds(10,825,250,25);
    
                            a.add(txtnumbering_charge);
                            txtnumbering_charge.setBounds(260,825,400,25);
                            txtnumbering_charge.setText("0");
                            a.add(lblperforation_charge);
                            lblperforation_charge.setBounds(10,855,250,25);
    
                            a.add(txtperforation_charge);
                            txtperforation_charge.setBounds(260,855,400,25);
                            txtperforation_charge.setText("0");
    
                            a.add(lbltotal_cost);
                            lbltotal_cost.setBounds(10,890,250,25);
    
                            a.add(txttotal_cost);
                            txttotal_cost.setBounds(260,890,400,25);
                            txttotal_cost.setText("0");
                            txttotal_cost.addFocusListener(this);
    
                            a.add(btnok);
                            btnok.setBounds(460,965,100,25);
                            btnok.addActionListener(this);
    
                            a.add(btncancel);
                            btncancel.setBounds(560,965,100,25);
                            btncancel.addActionListener(this);
    
                            // code for scrolling speed
                            //------------------------------------------------
                            abc.getVerticalScrollBar().setUnitIncrement(60);
                            abc.getVerticalScrollBar().setBlockIncrement(100);
                            //--------------------------------------------
    
                            
    
    
                            
                            this.getContentPane().add(abc);
                            show();
    
                           
    		}
    
    
    		public void actionPerformed(ActionEvent E)
    			{}
    
    		 public void focusGained(FocusEvent fe)
    			{}
    		
    		public void focusLost(FocusEvent fe)
    			{}
    Last edited by Fubarable; 09-10-2010 at 12:26 PM. Reason: Code tags added

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

    Default

    Moderator edit: code tags added to aid readability of the code. OP, to learn how to do this yourself, please read the link in my signature. Also I suggest that you re-read Darryl's link on how to create an SSCCE as your code above is not an SSCCE and most here will avoid reading it since it's too long and doesn't compile and run. Luck.

Similar Threads

  1. problem positioning a JPanel in a JScrollPane
    By gib65 in forum AWT / Swing
    Replies: 5
    Last Post: 09-06-2013, 08:27 AM
  2. JScrollPane problem
    By KArelVH in forum AWT / Swing
    Replies: 6
    Last Post: 04-27-2009, 09:40 PM
  3. problem with Jscrollpane
    By ravrajesh.ap in forum AWT / Swing
    Replies: 5
    Last Post: 01-03-2009, 10:38 PM
  4. JScrollPane updation Problem
    By goodwillwins in forum AWT / Swing
    Replies: 22
    Last Post: 09-28-2008, 09:11 AM
  5. jscrollpane problem
    By monkey04 in forum AWT / Swing
    Replies: 2
    Last Post: 01-19-2008, 05:23 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
  •