i have an imageViewer and i want to change the imagePanel into a TabbedPane so i can have more than one image open at the same time 开发者_如何学运维but have each of them in a different tab and be able to add and remove the tabs as well.
what i have:
private ImagePanel imagePanel; //<< i tried to change the ImagePanel to JTabbedPane but it doesn't work and it gives error in other parts of the codes that i have.
// Create the image pane in the center
imagePanel = new ImagePanel(); imagePanel.setBorder(new EtchedBorder()); contentPane.add(imagePanel, BorderLayout.CENTER);
the code above is for the image pane where the image is displayed. is it possible to change the image pane to a tabbedPane without changeing other bits in the code? i have looked at alot of tabbedpane examples but i don't know how to combine the code with my code to get it to work but i did put a few code examples into my program but the frame changes to tabbedpane and not the image pane where the image is displayed. i want to change the inner frame to tabbed not the actual frame of the program. any suggestions on how should i go about it or if you can show me a simple example that could work.
thank you
I imagine that your ImagePanel extends JPanel. You don't "change" this into a JTabbedPane, and in fact you can't, but rather you put it into a JTabbedPane. Please check out the tutorial on tabbed panes that will show you how to do this: How to use Tabbed Panes
One caveat: if you are using NetBeans drag-and-drop GUI creation tools to generate your Swing code, I advise you not to do this but rather to go through the Swing tutorials (one is linked to above) and learn to code Swing by hand. You won't regret this, and the extra knowledge gained can be used if later you need to create gui's with the NetBeans tool.
精彩评论