Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default Table for component

    Does somebody know how make a class which can show component in table which can increase component in this table by horizontally and vertically?

    I try something but I have problem with set a size...

    this class is inside class Tabulka (Table)
    Java Code:
    	private class ZmenaVelikostiHorizontalne {
    		/**	Prepážka, whitch is before */
    		private final Prepazka PREDCHOZI_PREPAZKA;
    		/**	Prepážka, whitch is now */
    		private final Prepazka SOUCASNA_PREPAZKA;
    		private int muzeSeMaximalneRoztahnout;
    		private final int muzeSeMinimalneZmensit = 10;
    
    		private final Component soucasna;
    		private final Component predchozi;
    		/** x of mouse where user press*/
    		private int zacalNa;
    		/**position where was Prepazka when user press the Prepazka*/
    		Point poziceSoucasne;
    		
    		private int sirkaPriZmacknutiSoucasne;
    		private int sirkaPriZmacknutiPredchozi;
    		private int ipadxSoucasnaStart;
    
    		ZmenaVelikostiHorizontalne(Component c, Component predchozi,
    				final Prepazka p, Prepazka predchoziPrepazka) {
    			this.SOUCASNA_PREPAZKA=p;
    			this.PREDCHOZI_PREPAZKA = predchoziPrepazka;
    			this.soucasna = c;
    			this.predchozi = predchozi;
    
                            akctivateOfListeneru(p);
    		}
    
    		private void akctivateOfListeneru(Prepazka p) {
    			p.addMouseListener(new MouseAdapter() {
    				@Override
    				public void mousePressed(MouseEvent e) {
    					zacalNa = MouseInfo.getPointerInfo().getLocation().x;
    
    					sirkaPriZmacknutiSoucasne = soucasna.getSize().width;//gbl.getConstraints(soucasne).ipadx;
    					sirkaPriZmacknutiPredchozi = predchozi.getSize().width;//gbl.getConstraints(predchozi).ipadx;
    					
    					poziceSoucasne=SOUCASNA_PREPAZKA.getLocation();
    
    					GridBagConstraints gbc = gbl.getConstraints(soucasna);
    					ipadxSoucasnaStart=gbc.ipadx;
    				}
    
    			});
    
    			p.addMouseMotionListener(new MouseMotionAdapter() {
    				@Override
    				public void mouseDragged(MouseEvent e) {
    
    					int xSoucasne = zacalNa- MouseInfo.getPointerInfo().getLocation().x;
    					posunutiSoucasne(xSoucasne);
    					setSize();
    				}
    			});
    		}
    
    		private void setSize(){
    			int predchoziX=0;
    			if(PREDCHOZI_PREPAZKA!=null)
    				predchoziX=PREDCHOZI_PREPAZKA.getPozice().x;
    			
    			int soucasnaX=SOUCASNA_PREPAZKA.getPozice().x;
    			
    				GridBagConstraints gbc = gbl.getConstraints(predchozi);
    				int ipadxPredchozi=soucasnaX-predchoziX;
    			
    				if(ipadxPredchozi<predchozi.getPreferredSize().width)
    						ipadxPredchozi=predchozi.getPreferredSize().width;
    				gbc.ipadx=ipadxPredchozi;
    				gbl.setConstraints(predchozi, gbc);
    				
    				
    				int ipadxSoucasna=ipadxSoucasnaStart-ipadxPredchozi+sirkaPriZmacknutiPredchozi;
    				
    				
    					if((ipadxSoucasna+soucasna.getSize().width)<soucasna.getPreferredSize().width)
    						ipadxSoucasna=0;
    				gbc = gbl.getConstraints(soucasna);
    				gbc.ipadx=ipadxSoucasna;
    				gbl.setConstraints(soucasna, gbc);
    				
    				soucasna.setMinimumSize(new java.awt.Dimension(ipadxSoucasna+soucasna.getPreferredSize().width,soucasna.getSize().width));
    		}
    		/**
    		 * shift Prepazka depend on mouse
    		 * 
    		 */
    		private void posunutiSoucasne(int o) {
    			SOUCASNA_PREPAZKA.setLocation(poziceSoucasne.x-o,poziceSoucasne.y);
    		}
    	}
    I am sorry but I am Czech and I writte this program by Czech... i hope you understand it...
    Last edited by VojtechSejkora; 11-26-2010 at 03:00 AM.

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

    Default

    I'm not sure that I fully understand your question, but perhaps you could use a JTable for your needs. You would likely need to create your own cell renderer and editor, but that's not too hard to do. For better help, consider posting the smallest compilable program that illustrates your problem.

  3. #3
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    And can I add to JTable for example JButton? I try it but it add only toString of this Component:(

  4. #4
    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 VojtechSejkora View Post
    And can I add to JTable for example JButton? I try it but it add only toString of this Component:(
    As far as I understand it, when viewing a cell, you can render a JButton, and when editing the cell you can show a JButton. But the Swing tutorials can show this better than I can explain it.

    Another option is to add a grid of JPanels to a container that uses GridLayout, and which is best for you will depend on your specific requirements.

  5. #5
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    when I would use GridLayout user could not set size of one component in row
    he can widen only all component in panel... but I want to user could widen single component.

    I hope you understand me...

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    can I add to JTable for example JButton?
    Take a look at this blog post by camickr:
    Table Button Column « Java Tips Weblog

    db

  7. #7
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    nice.... but I don't know what I will add to this Tabulka before when I add. I can add Label,Panel,Button,Choice all what is descendant of Component....

  8. #8
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    I need this.
    YouTube - a_Screen_Stream.avi
    commentary is in czech, but i hole you understand what i need

  9. #9
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    problem is done

    thanks all for help

    I forget to write validate() :-)

Similar Threads

  1. Cannot add component to JPanel
    By adi.shoukat in forum NetBeans
    Replies: 7
    Last Post: 12-10-2010, 11:12 PM
  2. Component to use ?
    By pbaudru in forum AWT / Swing
    Replies: 2
    Last Post: 02-17-2010, 09:55 AM
  3. Replies: 1
    Last Post: 01-08-2010, 06:19 AM
  4. Last focused component
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 2
    Last Post: 11-21-2009, 05:45 PM
  5. add component to component
    By Omarero in forum New To Java
    Replies: 7
    Last Post: 05-17-2009, 02:39 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
  •