Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (688)
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 2197 times)
0 Members and 1 Guest are viewing this topic.
Offline nonnus29

Senior Devvie

Giving Java a second chance after ludumdare fiasco

« Posted 2004-03-01 20: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:

            JTabbedPane tabbedPane = new JTabbedPane();
            JPanel appletpanel = new JPanel(new BorderLayout(),false);
            applet=new jsgcApplet();
        editor=new JEditorPane();
            JScrollPane editorpane = new JScrollPane(editor);
            tabbedPane.add("Script Editor",editorpane);

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 02: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!
Offline cfmdobbie

Senior Devvie

Medals: 1

Who, me?

« Reply #2 - Posted 2004-03-04 20: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

Exp: 12 years

Where's the Kaboom?

« Reply #3 - Posted 2004-03-04 22: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 Devvie

Giving Java a second chance after ludumdare fiasco

« Reply #4 - Posted 2004-03-05 18: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 03:06:57 »


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!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (73 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (79 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (111 views)
2015-10-18 23:29:12

DarkCart (137 views)
2015-10-16 00:58:11

KaiHH (118 views)
2015-10-11 14:10:14

KaiHH (158 views)
2015-10-11 13:26:18

BurntPizza (172 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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‑
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!