Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2005

Tip: Looking for answers? Try searching our database.

Tabbed panels

Thread view: 
al - 06 Apr 2005 02:28 GMT
Hi all, I have read stuff on this but still dont get it. I need to draw
a box and a circle on two different tab panels.
Here is what I have so far somthing is not in the right place.
I have looked at the tutorial thats on Sun's site but didnt help.
I'm new to Java and am trying to learn but somtimes I just dont get it.
what I was trying to do was when you select another tab the oval or
square is drawn.
If you can help or point me in the right direction I would appricaiate
it.

Allen

public class Frame1 extends JFrame
{
 private JTabbedPane jTabbedPane1 = new JTabbedPane();
 private Graphics g;
 private JTabbedPane jTabbedPane2 = new JTabbedPane();
 private JTabbedPane jTabbedPane3 = new JTabbedPane();

 public Frame1()
 {
   try
   {
     jbInit();
   }
   catch(Exception e)
   {
     e.printStackTrace();
   }

 }

 private void jbInit() throws Exception
 {
   this.getContentPane().setLayout(null);
   this.setSize(new Dimension(400, 300));
   jTabbedPane1.setBounds(new Rectangle(55, 30, 290, 225));
   jTabbedPane1.addTab("jTabbedPane2", jTabbedPane2);
   jTabbedPane1.addTab("jTabbedPane3", jTabbedPane3);
   // Register a change listener
   jTabbedPane1.addChangeListener(new ChangeListener() {
       // This method is called whenever the selected tab changes

public void stateChanged(ChangeEvent evt) {
           JTabbedPane jTabbedPane1 = (JTabbedPane)evt.getSource();

           // Get current tab
           int sel = jTabbedPane1.getSelectedIndex();
           if(sel == 0){
           jTabbedPanel.g.drawOval(300,120,100,75);
           }
          g.drawRect(72,160,200,35);
       }
});
Arnaud Berger - 06 Apr 2005 08:05 GMT
Hi,

A few questions :

- why do you need several JTabbedPane ?
- on which component should the oval or square be drawn ?
- what is jTabbedPanel in your example (this object doesn't exist) ?
- where is the Graphics object set ?

Some advice :

-provide a runnable example if possible
-custom painting in a component should occur in its paintComponent(Graphics
g) method
-trying to get a Graphics object from a component, storing it and drawing on
it in other places than
paint...() methods won't succeed

Regards,

Arnaud

> Hi all, I have read stuff on this but still dont get it. I need to draw
> a box and a circle on two different tab panels.
[quoted text clipped - 50 lines]
>         }
> });
Johan Kütt - 06 Apr 2005 21:38 GMT
there are several ways for doing this:

====================================================
first:

---------------------
main class
.....
TabbedPane tabs = new TabbedPane();
tabs.addTab( "Circle", new Tab1Panel() );
tabbs.addTab( "Rectangle", new Tab2Panel() );
.....
---------------------
---------------------
class Tab1Panel extends JPanel {

    public Tab1Panel() {}

    public void paintComponent( Graphics g ) {

        // draw the circle
    }
}
---------------------
---------------------
class Tab2Panel extends JPanel() {

    public Tab2Panel() {}

    public void paintComponent( Graphics g ) {

        // draw the rectangle
    }
}
---------------------
=================================================

second:
JTabbedPane tabs = new JTabbedPane();
JPanel tab1 = new JPanel();
JPanel tab2 = new JPanel();
Graphics g1 = tab1.getGraphics();
Graphics g2 = tab2.getGraphics();

g1.drawCircle(...);
g2.drawRectangle(...);

tabs.addTab( "Circle", tab1 );
tabs.addTab( "Rectangle", tab2 );

=================================================

there are certaily other ways for solving this problem

johan

> Hi all, I have read stuff on this but still dont get it. I need to draw
> a box and a circle on two different tab panels.
[quoted text clipped - 7 lines]
>
> Allen


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.