Results 1 to 3 of 3
Thread: Components not showing
- 12-27-2009, 05:21 PM #1
Member
- Join Date
- Dec 2009
- Location
- Denmark
- Posts
- 5
- Rep Power
- 0
Components not showing
Hi.
I'm trying to add some components in several tabs, but they do not seem to be showing. I've tried to change around a lot of things and re-writing the whole thing, but I still can't get it to work.
It needs to be said that I'm writing Java as an hobby so I've not studied it, so you'd propably see many flaws.
Here's my sources:
core.java
start.javaPHP Code:import javax.swing.*; import java.awt.*; public class core { private JTabbedPane tab = new JTabbedPane(); private Component[] tabComponents = {new start(), new quests()}; private String[] tabCaptions = {"Start", "Quests"}; public static void main(String[] args) { core Engine = new core(); } public core(){ JFrame window = new JFrame("Window"); for(int i = 0; i <= tabComponents.length - 1; i++) { tab.addTab(tabCaptions[i], new JScrollPane(tabComponents[i])); } window.add(tab, BorderLayout.CENTER); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setSize(500, 300); window.setVisible(true); } }
PHP Code:import javax.swing.*; public class start extends JComponent{ public start() { add(new JLabel("Start")); } }(I used the PHP BB tags for the colouring, just not to confuse anyone)PHP Code:import javax.swing.*; public class quests extends JComponent{ public quests() { add(new JLabel("Quests")); } }
-
Your problem may be one of Swing layouts. If I remember correctly, a JComponent uses a null layout as its default layout manager, meaning you are responsible for the location and position of every component you add to it. If you were using a JPanel on the other hand, it would be using a FlowLayout as default, and you'd see your JLabel. Another solution is to set the layout yourself:
Java Code:// please note that class names should be capilatlized. class Quests extends JComponent { public Quests() { setLayout(new FlowLayout()); add(new JLabel("Quests")); } }
- 12-27-2009, 06:05 PM #3
Member
- Join Date
- Dec 2009
- Location
- Denmark
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Showing
By bostonstate in forum New To JavaReplies: 3Last Post: 08-25-2008, 07:49 PM -
Need Help showing text in JTextArea
By GuyFawkes in forum AWT / SwingReplies: 3Last Post: 05-05-2008, 09:19 AM -
Showing how to add Actions for KeyStrokes
By Java Tip in forum javax.swingReplies: 0Last Post: 04-23-2008, 08:17 PM -
Error Messages Not Showing Up
By nvidia in forum Web FrameworksReplies: 0Last Post: 04-07-2008, 10:41 PM -
Why isn't this showing?
By JToolTip in forum Java AppletsReplies: 2Last Post: 07-07-2007, 11:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks