Swing Problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2006
Posts: 4
Reputation: infested13 is an unknown quantity at this point 
Solved Threads: 0
infested13 infested13 is offline Offline
Newbie Poster

Swing Problem

 
1
  #1
Jan 3rd, 2006
im new with Swing..im having problem on gridbag layout(my classwork)... im trying to stick a header(label) and a scrollpane(with a JList attach to scrollpane) to a tabbedpane
which the outcome may look like this


but for some reason..my scrollpane doesnt want to show up...
i need some help and tips from you guys and girls..

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.UIManager;
  4. import javax.swing.*;
  5. import javax.swing.event.*;
  6. import java.util.*;
  7. import java.text.*;
  8.  
  9. //Start of Assign2
  10. public class Assign2
  11. {
  12. Dimension screenSize, frameSize; // screen size variables
  13. Font largeFont = new Font("Default", Font.BOLD, 18);
  14. JFrame thisFrame;
  15.  
  16.  
  17. //Standard constructor, most of the code for the program will be run from here
  18. public Assign2()
  19. {
  20. disclaimer();
  21. Assign2Frame frame = new Assign2Frame();
  22. frame.setSize(500,350); //Set Screen Size
  23. //frame.validate();
  24.  
  25. //Exit Listener
  26. frame.addWindowListener(new WindowAdapter()
  27. {
  28. public void windowClosing(WindowEvent e)
  29. {
  30. System.exit(0);
  31. }
  32. });
  33. frame.setVisible(true); //Must sets frame as visibles
  34.  
  35.  
  36. //Position the Frame to the centre of the screen, everytime the program starts
  37. // frame.setLocation((screenSize.width - frameSize.width) / 2,
  38. // (screenSize.height - frameSize.height) /2 );
  39. }
  40.  
  41. public static void main(String [] args)
  42. {
  43. try
  44. {
  45. UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  46. }
  47.  
  48. catch (Exception e)
  49. {
  50. e.printStackTrace();
  51. }
  52. new Assign2();
  53. }
  54.  
  55. public void disclaimer()
  56. {
  57. System.out.println("My work + Other ppl's help too");
  58. }
  59.  
  60. }
  61. //End

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.UIManager;
  4. import javax.swing.*;
  5. import javax.swing.event.*;
  6. import java.util.*;
  7. import java.text.*;
  8.  
  9. import javax.swing.JTabbedPane;
  10. import javax.swing.ImageIcon;
  11. import javax.swing.JLabel;
  12. import javax.swing.JPanel;
  13. import javax.swing.JFrame;
  14. import javax.swing.JComponent;
  15. import java.awt.BorderLayout;
  16. import java.awt.Dimension;
  17. import java.awt.GridLayout;
  18. import java.awt.event.KeyEvent;
  19.  
  20. //Start of Assign2Frame
  21. public class Assign2Frame extends JFrame
  22. {
  23. private JTabbedPane tabbedPane;
  24. private JPanel panel1;
  25. private JPanel panel2;
  26. private JPanel panel3;
  27. private JList list;
  28. private JScrollPane scroll;
  29.  
  30. public Assign2Frame()
  31. {
  32.  
  33. //Set the default window close operation
  34. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35.  
  36. this.setSize(new Dimension(500,350));
  37. this.setTitle("Geeky's DVD Database");
  38.  
  39. JPanel contentPane;
  40. contentPane = (JPanel)this.getContentPane();
  41.  
  42. BorderLayout borderLayout = new BorderLayout();
  43. contentPane.setLayout(borderLayout);
  44.  
  45. // Video Information
  46. JTabbedPane tabbedPane = new JTabbedPane();
  47. //Create new panel
  48. panel1 = new JPanel();
  49. tabbedPane.addTab("Video Information", panel1);
  50. //Panel1 = GridBagLayout
  51. panel1.setLayout(new GridBagLayout());
  52. GridBagConstraints c = new GridBagConstraints();
  53. c.gridx=0; c.gridy=0;
  54. c.anchor = GridBagConstraints.WEST;
  55. panel1.add(new JLabel("Video Database System"), c);
  56.  
  57. /*Panel1 = BorderLayout
  58.   panel1.setLayout(new BorderLayout());
  59.   panel1.add(new JLabel("<html><font size = 18><b>Video Database System</b></font></html>"), BorderLayout.NORTH);
  60.   */
  61. // JList in Panel1
  62. String[] titleDVD = {
  63. "Wargames",
  64. "Apt Pupil",
  65. "Pitch Black",
  66. "Swordfish",
  67. "Phantom Menace",
  68. "Attack of the Clones",
  69. "Dark City",
  70. "Cube",
  71. "Mask",
  72. "Dogma",
  73. "RoboTech",
  74. "Spiderman",
  75. "Daredevil",
  76. "Contact",
  77. "The Lost Boys",
  78. "Dune",
  79. "Mars Attacks",
  80. "Austin Powers",
  81. "The One",
  82. "Superman"
  83. };
  84.  
  85. c.gridx=0; c.gridy=1;
  86. JList list = new JList(titleDVD);
  87. JScrollPane scroll = new JScrollPane(list);
  88.  
  89.  
  90. //list.setMinimumSize(new Dimension(100,100));
  91.  
  92. scroll.getViewport().add(list);
  93.  
  94. // Genre Filter
  95. //Create new panel
  96. panel2 = new JPanel();
  97. tabbedPane.addTab("Genre Filter", panel2);
  98.  
  99. // Statistics
  100. //Create new panel
  101. panel3 = new JPanel();
  102. tabbedPane.addTab("Statistics", panel3);
  103.  
  104. getContentPane().add(tabbedPane);
  105. getContentPane().add(scroll);
  106.  
  107. setResizable(false);
  108. setVisible (true);
  109. }
  110. }
  111. //End
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Swing Problem

 
0
  #2
Jan 3rd, 2006
A JScrollPane will not be in any way visible itself unless and until there is a need to display the scrollbars (or you've done something to explicitly show those always).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 4
Reputation: infested13 is an unknown quantity at this point 
Solved Threads: 0
infested13 infested13 is offline Offline
Newbie Poster

Re: Swing Problem

 
0
  #3
Jan 3rd, 2006
im new to swing...so i kinda dont get what you mean.

i creating a TabbedPane..for some reason..my 2nd Tab's JScrollPane works fine..but for the 1st tab's JScrollPane..it just doesnt show

got any idea what's wrong?
*BUSY*Debugging Swing
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Swing Problem

 
0
  #4
Jan 3rd, 2006
Add some swing constants if it's not showing up. I can't remember exactly what they are, but it's something like: JScrollPane.ALWAYS or something like that.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 4
Reputation: infested13 is an unknown quantity at this point 
Solved Threads: 0
infested13 infested13 is offline Offline
Newbie Poster

Re: Swing Problem

 
0
  #5
Jan 3rd, 2006
thx for the help...i will try to look for the code in the api...

My new question:
how to group JLabels together? and put the grouping to a GridBagLayout?

i uploaded a picture...
im trying to group "Movie Time" "Duration" "Time Now" and "Estimated Finish Time"

thx in advance
cheers
Attached Thumbnails
2.jpg  
*BUSY*Debugging Swing
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Swing Problem

 
0
  #6
Jan 3rd, 2006
What do you mean by grouping labels?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 4
Reputation: infested13 is an unknown quantity at this point 
Solved Threads: 0
infested13 infested13 is offline Offline
Newbie Poster

Re: Swing Problem

 
0
  #7
Jan 3rd, 2006
ermm..what layout would you recommend? the picture i uploaded..my task is to create a similar one using swing..and im not sure how to do the "Movie Time" "Duration" "Time Now" and "Estimated Finish Time" part...

i used gridbaglayout but they("Movie Time" "Duration" "Time Now" and "Estimated Finish Time") .. move out of their assigned places...
*BUSY*Debugging Swing
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Swing Problem

 
0
  #8
Jan 4th, 2006
Use nested layout managers.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC