Note that there are some explanatory texts on larger screens.

plurals
  1. POJTabbedPane addTab in wrapper method not working
    primarykey
    data
    text
    <p>As part of my Diploma in Software Dev we have to create a Java GUI to manage a Soccer League. My group has produced numerous JPanels that in the click-through prototype we put into JTabbedPane. This worked fine up until now where I'm moving them into separate files and into a MVC layout.</p> <p>I'm using a window class to hold the top level JFrame and menubar and adding in the tabbed panes to that. This works fine in the constructor but when I remove them from the constructor and try to add them from the Bootstrap via the <code>Window.attachTabbedPanel(String name, JPanel panel)</code> it doesn't display but querying <code>tabbedPane.getTabCount()</code> display an incrementing number of tabs.</p> <p>Here's a stripped back set of code: The Bootstrap file:</p> <pre><code>public class Bootstrap { private Window mainWindow; public Bootstrap() { //Window class is our containing JFrame and JMenuBar mainWindow = new Window(); //Load up our view classes TestTab tab1 = new TestTab(); TestTab tab2 = new TestTab(); //Attach them mainWindow.attachTabbedPanel("Tab1", tab1.getScreen()); mainWindow.attachTabbedPanel("Tab2", tab2.getScreen()); } // Bootstrap() public gui.Window getWindow(){ return mainWindow; } } // Bootstrap </code></pre> <p>This is called by the Main file:</p> <pre><code>public class Main { public static void main(String[] args) { Bootstrap RunMVC = new Bootstrap(); gui.Window mainWindow = RunMVC.getWindow(); mainWindow.run(); } // main() } // Main </code></pre> <p>The problem starts here at the Window class, I've added in a <code>In Constructor</code> tab to check I haven't stuffed up the tabbedPane but it works fine at that point.</p> <pre><code>public class Window { private JFrame frame; private JMenuBar menuBarMain; private JMenu mnFile; private JTabbedPane tabbedPane; private int count; /** * Create the application. */ public Window() { //Build the frame frame = new JFrame(); frame.setBounds(100, 100, 1280, 800); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new CardLayout(0, 0)); //End Build frame TestTab conTab = new TestTab(); //Add the tabbed pane to hold the top level screens tabbedPane = new JTabbedPane(JTabbedPane.TOP); frame.getContentPane().add(tabbedPane, "name_1"); tabbedPane.addTab("In Consructor", conTab.getScreen()); count = 1; } public void attachTabbedPanel(String name, JPanel panel){ System.out.println("Window: adding Jpanel name: "+name); System.out.println("panel is a: "+panel); tabbedPane.addTab(name, panel); tabbedPane.updateUI(); System.out.println("Number of tabs: "+tabbedPane.getTabCount()); System.out.println("Last Tab .isEnabledAt() "+tabbedPane.isEnabledAt(count++)); tabbedPane.updateUI(); } /** * Launch the window. */ public void run() { EventQueue.invokeLater(new Runnable() { public void run() { try { Window window = new Window(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } } </code></pre> <p>And lastly the Panel:</p> <pre><code>public class TestTab { private JPanel screen; private JLabel lblSeason; private JButton btnEdit; private JLabel lblRounds; public JPanel getScreen() { return screen; } /** * Initialize the contents of the frame. */ public TestTab() { screen = new JPanel(); screen.setLayout(new MigLayout("", "[8%,right][10%,left][8%,right][10%,left][grow][50%]", "[][][grow]")); lblSeason = new JLabel("Test"); screen.add(lblSeason, "flowx,cell 0 0"); btnEdit = new JButton("Edit Test"); screen.add(btnEdit, "cell 5 0,alignx right"); lblRounds = new JLabel("More Testing"); screen.add(lblRounds, "cell 0 1,alignx left"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload