Results 1 to 14 of 14
- 09-30-2010, 10:36 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
adding JList and JButton to a TabbedPane
Hi,
Can someone tell me how I can add a JButtons or JLists on a Tabbedpane. I'm using the code below from the java tutorial but when use the add(list) then it gets added on a different tab.
String[] data = {"one","two","three"};
JComponent panel1 = makeTextPanel("Panel #1");
tabbedPane.addTab("Tab 1", icon, panel1,
"does nothing");
tabbedPane.add(list);
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
Thanks !!!!.
-
You would add a JPanel to the JTabbedPane (not a JComponent), and you add the other components (JButton, JLIst) to this same JPanel.
- 09-30-2010, 01:11 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
Thanks for that again. Question about loading/populating my JList with the keys from my hashMap. If I use the keyset how I can add this into the JList if the JList only accepts Arrays.
-
Have the JList use a DefaultListModel and iterate through the Set (it's iterable), adding to the model as you go.
- 10-01-2010, 12:39 AM #5
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
thanks again!!!. Very very usefull tips you have given me. I'll try the DefaultListModel .Thanks...
- 10-01-2010, 11:17 AM #6
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
Actually I wonder if I can ask another question. Now I'm adding multiple JList's and JButton's to each JPanel but even though I'm specifying the Alignments (north,west,east and so on) they are all going to the centre. Also I need to add JLabel's on top of these Jlist's but not sure how I can put them where I want them. Thanks for your valuable help!!.
- 10-01-2010, 12:33 PM #7
Use an appropriate layout manager. Only BorderLayout has NORTH, WEST etc.
Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Are your JLists in JScrollPanes (if not, they probably should be). If they are,Also I need to add JLabel's on top of these Jlist's but not sure how I can put them where I want them.
JScrollPane (Java Platform SE 6))
db
- 10-03-2010, 11:06 PM #8
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
Thanks Darryl for your message. I wonder if I need to use a layout manager where I can specify all by hand without relying on Netbeans which one would be the ideal one. I have to fit only 5 Jlist and the same number of JLabel on a JPanel.
- 10-04-2010, 01:09 AM #9
You can get by without a layout manager, if you want to make your code difficult to maintain.
db
-
- 10-05-2010, 04:21 AM #11
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
Actually I managed to create the GUI using BorderLayout but I have another question. It might sounds silly but I'm using a multiple JList's and using listModel to load the items into the JList but what I did all this basically adding the data Structure (HashMap) in the same class as the GUI class so Hashmap is visible/accesable but now I wonder because I have a bunch of HashMaps define on my driver class what do a need to do so I can load all my JList's. So to recap I have my GUI class and I have a DRIVER class where all my data structures are defined. What do I need to do to make then visible to the GUI class. Thanks!!!. Sorry for my ignorance but my OO skill are very poor.Thanks again.
- 10-05-2010, 05:53 AM #12
Search the web for MVC, it looks like your application has just attained the complexity that requires a systematic break-up.
luck, db
- 10-06-2010, 12:09 AM #13
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
Thanks again Darryl. I'll have a look. Now I have another question. I wonder why I have created my TabbedPane succefully and in one of the TabbbedPane I have added JPanels. I wonder why the size of the JPanel remains so small even I have specified to make it bigger size. Where do I have to specify the size so I can make the containers inside the TabbedPane bigger. Thanks!!!
-
Similar Threads
-
Adding to JList with Netbeans
By kewlgeye in forum NetBeansReplies: 7Last Post: 03-28-2012, 07:39 PM -
Adding \ removing items from Jlist
By Desperado in forum AWT / SwingReplies: 10Last Post: 12-17-2009, 12:48 PM -
Adding JButton to a JTable
By ting.at.net@hotmail.com in forum AWT / SwingReplies: 6Last Post: 05-26-2009, 03:37 AM -
adding Image to JButton
By mayhewj7 in forum New To JavaReplies: 3Last Post: 03-31-2009, 03:39 AM -
JList and JButton event handler not working
By H3rtaherta in forum AWT / SwingReplies: 3Last Post: 11-22-2008, 12:00 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks