Results 1 to 4 of 4

Thread: panel resizing

  1. #1
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default panel resizing

    Hello,

    I am using a free layout and I am using panel.getGraphics method to draw. I figured it out that the panel size is not resizing . COuld someone guide me how to overcome that. I am using net beans .

    Thanks in Advance
    kumar

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

    Default

    We need a bit more information. Also you may be using a wrong layout manager. have you gone over the layout manager tutorial at the Sun Swing tutorials? If not, you should as it will help you.

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

    Default

    I have added the code for your kind reference. I am trying draw some vertical lines in drawPanel and the size is not changing. So I am unable to use the scrollbar. I didnt use any layout managers as I used netbeans and the layout manager I used is freedesign just drag and drop.
    I suggest that you learn how to use other layout managers, managers that may help you resize your panel better. You can read up on them here: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI with JFC/Swing)

    Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]

  4. #4
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    I am really sorry. Thank you for your help.
    Java Code:
    //code to draw vertical lines
    
    
    
    
    
    Graphics g = drawPanel.getGraphics();
    
    
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G,RenderingHints.VALUE_ANTIALIAS_ON);
    
    
    int dwidth = 0;
    dwidth = (width/20) ;//10=processmax
    
    if(dwidth < 30)
    {
    dwidth = 70;
    }
    
    int dheight = 0;
    dheight = height - 50;
    
    
    
    
    int x1 = 30 ; //left
    int y1 = 50; //top --- Constant value
    int x2 = 30 ; //right
    int y2 = dheight; //bottom
    int y3 = y1-10; //for process no. string
    int x3 = x1-5;
    
    for (int i = 0;i <= 20;i++)
    {
    g2.setColor(Color.BLACK);
    g2.drawLine(x1, y1, x2, y2);
    g2.setColor(Color.BLUE);
    g2.drawString("P"+i,x3 , y3);
    x1 = (x1 + dwidth);
    x2 = (x2 + dwidth);
    x3 = (x1 - 10);
    
    }
    
    
    
    int height1 = drawPanel.getHeight();
    int width1 = drawPanel.getWidth();
    System.out.println("Height of DrawPanel new " + height1);
    System.out.println("Width of DrawPanel new " + width1);
    
    JScrollPane scroll = new JScrollPane(drawPanel);
    
    scroll.setSize(600,800);
    if(drawPanel .getSize().height > scroll.getSize().height)
    { scroll.createVerticalScrollBar(); }
    
    if(drawPanel.getSize().width>scroll.getSize().widt h)
    { scroll.createHorizontalScrollBar(); }

Similar Threads

  1. Replies: 4
    Last Post: 01-13-2011, 05:30 PM
  2. Image Resizing and DPi
    By Rob_ in forum Java Applets
    Replies: 4
    Last Post: 11-27-2008, 02:21 PM
  3. panel positioning
    By shwein in forum New To Java
    Replies: 4
    Last Post: 09-09-2008, 05:15 PM
  4. add image on panel
    By samiksha.goel in forum AWT / Swing
    Replies: 4
    Last Post: 08-02-2008, 07:38 PM
  5. Image resizing
    By alley in forum Java 2D
    Replies: 2
    Last Post: 11-13-2007, 10:10 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
  •