I am having problems understanding why two JPanels do not display correctly in the JTabbedPane container I have created. (the other two do display correctly, with different LayoutManagers for each]
WebBrowser is has line with URL browswer line
and then a JEditorPane. [I copied the code for this pane straight from our assignment in my classroom, but in class we just used a JFrame for a container, not a JTabbedPane extending a JFrame, and JPanels inside the JTabbedPane] Can you put a JEditorPane inside a JPane, inside a JTabbedPane?
TaxReport just has simle JLabels and three separate JPanels in a BorderLayout
Why do these not display correctly?
STARTUP MAIN CLASS
WEBBROWSER CLASSCode:import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*; public class StartUp extends JFrame implements ActionListener { JFrame frame = new JFrame("Tool Inventory"); JTabbedPane jtp = new JTabbedPane(); InputPanel tab1 = new InputPanel(); SearchPanel tab2 = new SearchPanel(); ShowPanel tab3 = new ShowPanel(); WebBrowser tab4 = new WebBrowser(); TaxReport tab5 = new TaxReport(); /** Creates a new instance of StartUp */ public StartUp() { frame.setSize(650,500); frame.setLocation(75,30); frame.getContentPane().add(jtp); jtp.add("Input Tool", tab1); jtp.add("Search File",tab2); jtp.add("Show File Contents",tab3); jtp.add("Search Web",tab4); jtp.add("Tax Report",tab5); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setVisible(true); } public static void main(String[] args) { new StartUp(); } public void actionPerformed(ActionEvent e) { } }
TAXREPORT CLASSCode:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.net.*; import java.io.*; public class WebBrowser extends JPanel implements ActionListener,HyperlinkListener { URL url; JLabel urlLine = new JLabel("URL"); JTextField text = new JTextField(30); JEditorPane edit= new JEditorPane(); public WebBrowser() { this.setSize(400,400); this.setLocation(10, 10); edit.setEditable(false); text.addActionListener(this); edit.addHyperlinkListener(this); this.add(urlLine,BorderLayout.NORTH); this.add(text,BorderLayout.NORTH); this.add(edit,BorderLayout.CENTER); try { url = new URL("http://search.yahoo.com"); edit.setPage(url); } catch (Exception e) { } } public void actionPerformed(ActionEvent e) { try{ URL browserLine = new URL(text.getText()); edit.setPage(browserLine); } catch (Exception error) { } } public void hyperlinkUpdate(HyperlinkEvent e) { HyperlinkEvent.EventType type = e.getEventType(); try { if (type==HyperlinkEvent.EventType.ACTIVATED) edit.setPage(e.getURL()); else if (type==HyperlinkEvent.EventType.ENTERED) text.setText(e.getURL()+""); else if (type==HyperlinkEvent.EventType.EXITED) text.setText(""); } catch (Exception ex) { } } }
Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class TaxReport extends JPanel implements ActionListener { //containters JPanel top = new JPanel(); JPanel middle = new JPanel(); JPanel bottom = new JPanel(); //components on container in NORTH JLabel taxRept = new JLabel("TAX REPORT"); //components on container in CENTER JLabel taxYearLabel = new JLabel("Tax Year:"); JLabel taxYear = new JLabel(); JLabel toolsBoughtLabel = new JLabel("Total Tools Bought:"); JLabel toolsBought = new JLabel(); JLabel toolsDollarsLabel = new JLabel("Total Tool Dollars"); JLabel toolsDollars = new JLabel(); //components on containter in SOUTH JButton total = new JButton("Display Totals"); JButton printButton = new JButton("Print"); /** Creates a new instance of TaxReport */ public TaxReport() { super(); setSize(400,400); setLocation(20,20); //component added to NORTH top.add(taxRept); //components added to CENTER middle.add(taxYearLabel); middle.add(taxYear); middle.add(toolsBoughtLabel); middle.add(toolsBought); middle.add(toolsDollarsLabel); middle.add(toolsDollars); //components added to SOUTH bottom.add(total); total.addActionListener(this); bottom.add(printButton); printButton.addActionListener(this); //containers on JPanel add(top); add(middle,new GridLayout(5,2)); add(bottom); } public void actionPerformed(ActionEvent e) { } }


Reply With Quote


Bookmarks