draw to a Tab


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: draw to a Tab

  1. #1
    Join Date
    Feb 2003
    Posts
    6

    draw to a Tab

    Hi,

    In Java, is there a way to take a Rectrangle or Line
    such as the following and place it in a JTabbedPane?

    g.drawRect(0, 0,width, height);

    g.drawLine(x, y, width, height);

    addTab(???);

    Would I have to create a JPanel?

    How would I do this?

    Your help in understanding this is appreciated.

  2. #2
    Join Date
    Mar 2003
    Posts
    86

    Easy

    Very easy.

    Have a class that subclasses JPanel.
    Add you class to the JTabbedPane as a new tab.

    Overide paint, and paint you two rects.

    Sharbov.

  3. #3
    Join Date
    Feb 2003
    Posts
    6

    Is this what you mean?

    Is the following what you mean? If so, how would I add this class to a TabbedPane?

    public class DrawLine extends JPanel
    {
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    Graphics2D g2D = (Graphics2D)g;

    int i = 3;
    g.drawLine(x, (int)f(x), (test[1]), (int)f((test[2])));
    while(i != test.length)
    {

    g.drawLine(test[i-2],(int)f((test[i-1])),(test[i]),(int)f(test[i+1]));

    i = i+2;

    }

    }
    }

  4. #4
    Join Date
    Mar 2003
    Posts
    86

    addTab

    Assuming you hold a member of JTabbedPane, after you create it, and add it to the main contect pain, just use addTab, and pass your DrawLine object.

    Sharbov.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center