Results 1 to 7 of 7
- 07-07-2015, 03:00 AM #1
Member
- Join Date
- Jul 2015
- Posts
- 2
- Rep Power
- 0
Not adding a jpanel to a frame makes other jpanel not show up
Java Code:package mapEditor; import java.awt.Color; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JRadioButton; import javax.swing.JScrollPane; public class TwoD2 extends JFrame{ private static final long serialVersionUID = 1L; JPanel optionsPanel, whichGroundPanel, backgroundPanel; MapPiecesPanel mapPiecesPanel; JScrollPane mapPiecesScrollPane; JRadioButton bgButton, mgButton, fgButton; ButtonGroup gButtonGroup; public JProgressBar progressBar; JScrollPane mapScrollPane; public static JMenuBar menuBar; public static JMenu menu; public static JMenu subMenu; public static JMenuItem menuItem; MapPanel mapPanel; public static TwoD2 twoD2; both.InitDatabase initDatabase; both.LoadImages loadImages; public static both.MySql mySql; public static void main (String args[]){ twoD2 = new TwoD2(); twoD2.initialize(); } private void initialize() { //START BUGFIX [B][U]backgroundPanel = new JPanel(); backgroundPanel.setBackground(Color.WHITE); backgroundPanel.setBounds(0, 0, 870, 680); twoD2.add(backgroundPanel); //END BUGFIX twoD2.setJMenuBar(returnJMenuBar()); twoD2.setVisible(true); twoD2.setSize(870, 680); twoD2.setLayout(null); twoD2.setResizable(true); mySql = new both.MySql(); initDatabase = new both.InitDatabase(); loadImages = new both.LoadImages(); doMapScrollPane(); doMapPiecesScrollPane(); twoD2.add(mapPiecesScrollPane); twoD2.add(mapScrollPane); twoD2.revalidate(); twoD2.repaint(); } TwoD2(){ whichGroundPanel = new JPanel(); whichGroundPanel.setLayout(null); bgButton = new JRadioButton("Bg: "); bgButton.setBounds(0, 0, 60, 20); mgButton = new JRadioButton("Mg: "); mgButton.setBounds(0, 20, 60, 20); fgButton = new JRadioButton("Fg: "); fgButton.setBounds(0, 40, 60, 20); gButtonGroup = new ButtonGroup(); gButtonGroup.add(bgButton); gButtonGroup.add(mgButton); gButtonGroup.add(fgButton); whichGroundPanel.add(bgButton); whichGroundPanel.add(mgButton); whichGroundPanel.add(fgButton); whichGroundPanel.setBounds(0, 5, 50, 60); progressBar = new JProgressBar(); progressBar.setValue(100); progressBar.setStringPainted(true); progressBar.setBorder(BorderFactory.createTitledBorder("Busy...")); progressBar.setBounds(735, 5, 120, 60); optionsPanel = new JPanel(); optionsPanel.setLayout(null); optionsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.black)); optionsPanel.add(whichGroundPanel); optionsPanel.add(progressBar); optionsPanel.setBounds(0, 545, 870, 70); add(optionsPanel); } private void doMapScrollPane() { mapPanel = new MapPanel(); mapPanel.addMouseListener(new MapPanelMouseListener()); mapPanel.addMouseMotionListener(new MapPanelMouseListener()); mapPanel.setPreferredSize(new Dimension(both.Variabelen.size[0]*50, both.Variabelen.size[1]*50)); mapScrollPane = new JScrollPane(mapPanel); mapScrollPane.setWheelScrollingEnabled(false); mapScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); mapScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); mapScrollPane.getVerticalScrollBar().setUnitIncrement(50); mapScrollPane.getHorizontalScrollBar().setUnitIncrement(50); mapScrollPane.setBounds(0, 0, 800, 545); } private void doMapPiecesScrollPane(){ mapPiecesPanel = new MapPiecesPanel(); mapPiecesScrollPane = new JScrollPane(mapPiecesPanel); mapPiecesScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); mapPiecesScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); mapPiecesScrollPane.getVerticalScrollBar().setUnitIncrement(50); mapPiecesScrollPane.setPreferredSize(new Dimension(50, 670)); mapPiecesScrollPane.setBounds(800, 0, 70, 545); } private JMenuBar returnJMenuBar(){ menuBar = new JMenuBar(); menu = new JMenu("Opties"); menuBar.add(menu); menuItem = new JMenuItem("Save"); menu.add(menuItem); return menuBar; } }
Java Code:package mapEditor; import java.awt.Color; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JRadioButton; import javax.swing.JScrollPane; public class TwoD2 extends JFrame{ private static final long serialVersionUID = 1L; JPanel optionsPanel, whichGroundPanel, backgroundPanel; MapPiecesPanel mapPiecesPanel; JScrollPane mapPiecesScrollPane; JRadioButton bgButton, mgButton, fgButton; ButtonGroup gButtonGroup; public JProgressBar progressBar; JScrollPane mapScrollPane; public static JMenuBar menuBar; public static JMenu menu; public static JMenu subMenu; public static JMenuItem menuItem; MapPanel mapPanel; public static TwoD2 twoD2; both.InitDatabase initDatabase; both.LoadImages loadImages; public static both.MySql mySql; public static void main (String args[]){ twoD2 = new TwoD2(); twoD2.initialize(); } private void initialize() { twoD2.setJMenuBar(returnJMenuBar()); twoD2.setVisible(true); twoD2.setSize(870, 680); twoD2.setLayout(null); twoD2.setResizable(true); mySql = new both.MySql(); initDatabase = new both.InitDatabase(); loadImages = new both.LoadImages(); doMapScrollPane(); doMapPiecesScrollPane(); twoD2.add(mapPiecesScrollPane); twoD2.add(mapScrollPane); twoD2.revalidate(); twoD2.repaint(); } TwoD2(){ whichGroundPanel = new JPanel(); whichGroundPanel.setLayout(null); bgButton = new JRadioButton("Bg: "); bgButton.setBounds(0, 0, 60, 20); mgButton = new JRadioButton("Mg: "); mgButton.setBounds(0, 20, 60, 20); fgButton = new JRadioButton("Fg: "); fgButton.setBounds(0, 40, 60, 20); gButtonGroup = new ButtonGroup(); gButtonGroup.add(bgButton); gButtonGroup.add(mgButton); gButtonGroup.add(fgButton); whichGroundPanel.add(bgButton); whichGroundPanel.add(mgButton); whichGroundPanel.add(fgButton); whichGroundPanel.setBounds(0, 5, 50, 60); progressBar = new JProgressBar(); progressBar.setValue(100); progressBar.setStringPainted(true); progressBar.setBorder(BorderFactory.createTitledBorder("Busy...")); progressBar.setBounds(735, 5, 120, 60); optionsPanel = new JPanel(); optionsPanel.setLayout(null); optionsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.black)); optionsPanel.add(whichGroundPanel); optionsPanel.add(progressBar); optionsPanel.setBounds(0, 545, 870, 70); add(optionsPanel); } private void doMapScrollPane() { mapPanel = new MapPanel(); mapPanel.addMouseListener(new MapPanelMouseListener()); mapPanel.addMouseMotionListener(new MapPanelMouseListener()); mapPanel.setPreferredSize(new Dimension(both.Variabelen.size[0]*50, both.Variabelen.size[1]*50)); mapScrollPane = new JScrollPane(mapPanel); mapScrollPane.setWheelScrollingEnabled(false); mapScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); mapScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); mapScrollPane.getVerticalScrollBar().setUnitIncrement(50); mapScrollPane.getHorizontalScrollBar().setUnitIncrement(50); mapScrollPane.setBounds(0, 0, 800, 545); } private void doMapPiecesScrollPane(){ mapPiecesPanel = new MapPiecesPanel(); mapPiecesScrollPane = new JScrollPane(mapPiecesPanel); mapPiecesScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); mapPiecesScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); mapPiecesScrollPane.getVerticalScrollBar().setUnitIncrement(50); mapPiecesScrollPane.setPreferredSize(new Dimension(50, 670)); mapPiecesScrollPane.setBounds(800, 0, 70, 545); } private JMenuBar returnJMenuBar(){ menuBar = new JMenuBar(); menu = new JMenu("Opties"); menuBar.add(menu); menuItem = new JMenuItem("Save"); menu.add(menuItem); return menuBar; } }
The JPanel not showing up being optionsPanel.
Willing to post SSCCE if it is needed. Probably missing something/doing something wrong.
Will be here for any questions and or information needed.
Thanks already!Last edited by Kjevo; 07-07-2015 at 09:48 AM.
- 07-07-2015, 06:54 AM #2
Re: Not adding a jpanel to a frame makes other jpanel not show up
What bold underlined part?
Stop using setBounds(...). Learn to use layout managers: Lesson: Laying Out Components Within a Container (The Javaâ„¢ Tutorials > Creating a GUI With JFC/Swing)
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-07-2015, 06:55 AM #3
Re: Not adding a jpanel to a frame makes other jpanel not show up
Also don't use setPreferredSize(...)
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-07-2015, 06:56 AM #4
Re: Not adding a jpanel to a frame makes other jpanel not show up
Moved from New to Java to AWT/Swing.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-07-2015, 09:47 AM #5
Member
- Join Date
- Jul 2015
- Posts
- 2
- Rep Power
- 0
Re: Not adding a jpanel to a frame makes other jpanel not show up
Het DB! Thanks for the interest in my problem! I changed it since bold/underline doesn't seem to work in code tags.
It's between comments now. Adding that part makes it so that the other(optionsPanel) becomes visible.
And i am not using a layout manager because i want more control, If i were to use one which one would you recommend?
Thanks!Last edited by Kjevo; 07-07-2015 at 09:50 AM.
- 07-07-2015, 09:15 PM #6
Re: Not adding a jpanel to a frame makes other jpanel not show up
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-08-2015, 12:03 AM #7
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Not adding a jpanel to a frame makes other jpanel not show up
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
Similar Threads
-
Adding JPanel to JPanel not showing
By rru96 in forum AWT / SwingReplies: 5Last Post: 08-11-2013, 05:45 AM -
Scrolling in JPanel makes the content erased
By Mathi_r in forum Java AppletsReplies: 3Last Post: 07-28-2011, 03:01 PM -
Adding a jpanel to a customized Jpanel Class
By trishtren in forum AWT / SwingReplies: 7Last Post: 04-05-2011, 07:52 PM -
Adding Jpanel ontop of another Jpanel
By Manfizy in forum AWT / SwingReplies: 4Last Post: 03-05-2011, 11:34 PM
Bookmarks