Note that there are some explanatory texts on larger screens.

plurals
  1. POwritting a button that creates a tab, i need to pass some information to the new tab?
    primarykey
    data
    text
    <p>I am writing a program with JTabbed Panes. I want to have a button that gets some text from a JTextField, uses that text to create a new tab. The new tab will contain the name = Jtextfield.getText(), and it will print it in a JTextArea 10 times.</p> <p>My real question is, how do I pass some data to an ActionListener for a button, or how would I go around that, because it is causing me trouble?</p> <p>UPDATE:</p> <p>Here is my attempt to solve this. I know the code is complicated, I'm a horrible programmer. I hope that you can help me see what is going wrong here. I am afraid that my CreateComponent method and the CreateNewFeedBlock actionListener are going wrong.</p> <p>Here is some of my code, please bear with me. </p> <pre><code>private static JPanel mainPane; private JPanel categoryPanel; private JTextField categoryName; private JPanel panel1; private JTextField title1; private JTextField url1; private JPanel panel2; private JTextField title2; private JTextField url2; private JPanel panel3; private JTextField title3; private JTextField url3; private JPanel panel4; private JTextField title4; private JTextField url4; public BIS() { //unecessary code categoryPanel = new JPanel(); categoryPanel.setLayout(new GridLayout(2,2)); JLabel emptyLabel1 = new JLabel(""); JLabel emptyLabel2 = new JLabel(""); JLabel insertCategoryName = new JLabel("Category name:"); categoryName = new JTextField(20); panel1 = new JPanel(); panel1.setLayout(new GridLayout(2,2)); JLabel insertTitle1 = new JLabel("Feed Title:"); title1 = new JTextField(20); JLabel insertURL1 = new JLabel("URL:"); url1 = new JTextField(20); panel1.add(insertTitle1); panel1.add(title1); panel1.add(insertURL1); panel1.add(url1); categoryPanel.add(emptyLabel1); categoryPanel.add(emptyLabel2); categoryPanel.add(insertCategoryName); categoryPanel.add(categoryName); JPanel addPanel = new JPanel(new GridLayout(6,1)); JButton addButton = new JButton("Create Your RSS Show"); addPanel.add(categoryPanel); addPanel.add(panel1); addPanel.add(addButton); addPanel.setBorder(BorderFactory.createEmptyBorder(64, 64, 64, 64)); addButton.addActionListener(new CreateTab()); pane.add("Create Your Own", addPanel); Timer timer = new Timer(15000, new ActionListener() { public void actionPerformed(ActionEvent e) { allRun(); //System.out.println("U BO NIHER"); } }); timer.setRepeats(true); timer.setCoalesce(true); timer.start(); timer.restart(); } public class CreateTab implements ActionListener { public void actionPerformed(ActionEvent e) { panel = new JPanel(); while (!url1.getText().contains("http://")) { JOptionPane.showMessageDialog(panel, "The RSS Feed Link does not contain http//."); url1.setText(JOptionPane.showInputDialog("Please enter the full URL to the RSS Feed?")); } rssListForTab = new ArrayList&lt;rssInfo&gt;(); rssInfo feedInfo = new rssInfo(title1.getText(), url1.getText()); rssListForTab.add(feedInfo); rssListForAll.add(rssListForTab); final Component newTab = createComponent(panel, rssListForTab); pane.add(categoryName.getText(), newTab); // newTab.get // newTab.getComponent(2); categoryName.setText(""); title1.setText(""); url1.setText(""); } } private JComponent createComponent(JPanel panel, ArrayList&lt;rssInfo&gt; rssList) { JLabel t1 = new JLabel(title1.getText(), JLabel.CENTER); JTextArea u1 = new JTextArea(5,5); JScrollPane u1Scroll = new JScrollPane(u1); u1Scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); u1Scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); u1.setEditable(false); u1.setFont(new Font("Tahoma", Font.BOLD, 12)); u1.setLineWrap(true); u1.setWrapStyleWord(true); JButton addFeedButton = new JButton("Add Feed"); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.add(addFeedButton); panel.add(t1); panel.add(u1Scroll); panel.setSize(1,1); panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); addFeedButton.addActionListener(new createNewFeedBlock()); return panel; } public class createNewFeedBlock implements ActionListener { public void actionPerformed(ActionEvent e) { rssInfo newFeedInfo = DisplayDialog(); JLabel t2 = new JLabel(newFeedInfo.getTitle(), JLabel.CENTER); JTextArea u2 = new JTextArea(5,5); JScrollPane u2Scroll = new JScrollPane(u2); u2Scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); u2Scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); u2.setEditable(false); u2.setFont(new Font("Tahoma", Font.BOLD, 12)); u2.setLineWrap(true); u2.setWrapStyleWord(true); rssListForTab.add(newFeedInfo); panel.add(t2); panel.add(u2Scroll); } } </code></pre> <p>I think that the problem consists inside the CreateNewFeedBlock and/or createComponent method. I know this code is very hard to read, but please see if you can help me somehow on finding what is going wrong. </p> <p>Please look at anything that you see wrong and just tell me, I am doing my best to solve this but I'm helpless. I hope that your help will take me through this challenge.</p> <p><strong>UPDATE**</strong></p> <p>This code is not working properly, whenever I click addFeedButton, instead of adding one feed to the corresponding tab where it is being invoked from, it adds one feed to all the tabs in the pane.</p> <p>I am pretty sure it is a variable scope problem, could somebody help me find a way around it? Thank you!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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