Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Centering an Applet in a JTabbedPane?  (Read 1777 times)
0 Members and 1 Guest are viewing this topic.
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Posted 2004-03-01 21:58:01 »

I've been playing with this for some time and I haven't been able to get my applet to center in the middle of a tabbed pane in my jframe:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
            JFrame.setDefaultLookAndFeelDecorated(false);
           
            setSize(500,500);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBackground(Color.gray);
            JTabbedPane tabbedPane = new JTabbedPane();
           
            JPanel appletpanel = new JPanel(new BorderLayout(),false);
            applet=new jsgcApplet();
        appletpanel.add(applet,BorderLayout.CENTER);
       
        editor=new JEditorPane();
            JScrollPane editorpane = new JScrollPane(editor);
           
            tabbedPane.add("Display",appletpanel);
            tabbedPane.add("Script Editor",editorpane);
           
            getContentPane().add(tabbedPane,BorderLayout.CENTER);
           
            applet.init();
            applet.start();
           
            setVisible(true);


Does anyone see anything blatantly wrong with my code?

Edit:  With this code it is set at the top right corner
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2004-03-03 03:56:37 »

Hmm. Seperate the issues.  See if it centers in the BorderLAyout pane (it should) and then see what happens if you just add something ofa  known size to the tabbed pane.

Also you might want to try doing a pack() befoer you set it visible

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #2 - Posted 2004-03-04 21:47:36 »

BorderLayout.CENTER will add the applet to the panel's center region, but that doesn't say anything about its actual alignment, does it?  I would have expected it to be expanded to fill the whole panel, but you say that's not what's happening.  Maybe it is, but the panel isn't where you think it is?

If you're using layout managers, a pack() in the right place can mean the difference between expected operation and absolute bedlam, in my experience - Jeff is dead right about that.

Otherwise, if you know the sizes of everything involved, you might find it easier to set the layout manager to null and position the applet in absolute coordinates.  Be careful of insets though.

When debugging GUI layouts, it's often handy to give everything different background colours until you're sure things are performing as you'd expect - this makes unexpected behaviour much easier to spot.

Hellomynameis Charlie Dobbie.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #3 - Posted 2004-03-04 23:22:51 »

Sometimes different background colors don't help if the component is not opaque.  You can call setOpaque(true), or sometimes I use borders to get a similar effect.

Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #4 - Posted 2004-03-05 19:27:01 »

Well, I've using pack() and no effect on the problem.  I replace the applet with a label and the label centered fine.

My next question is:  Is a JApplet a heavyweight component?  In looking over the jdocs I see that JApplet inherits from java.awt.Applet and not javax.swing.  So maybe thats my problem....
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2004-03-06 04:06:57 »

UMph.

Are you trying to use JAPplet AS a component?

Lots of luck, its a base container, like a JFrame.  And yes I believe its heavyweight.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (37 views)
2014-07-24 01:59:36

Riven (38 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (58 views)
2014-07-18 06:55:21

Zero Volt (49 views)
2014-07-17 23:47:54

danieldean (41 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!