Results 1 to 5 of 5
- 12-21-2009, 12:15 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 4
- Rep Power
- 0
Accessing class defined within a constructor
Is there a way to access a class defined within a constructor and if their isn't how can i change value of specific cell from the main method.
PHP Code:import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class SimpleTableDemo extends JPanel { public SimpleTableDemo() { super(new GridLayout(1,0)); String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane); //------------------------------------------ class wewn { public void mma() { table.setValueAt(new String("qqq"),1,1); } } //------------------------------------------- } private static void createAndShowGUI() { JFrame frame = new JFrame("SimpleTableDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SimpleTableDemo newContentPane = new SimpleTableDemo(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { SimpleTableDemo fff = new SimpleTableDemo(); fff.createAndShowGUI(); } }
- 12-21-2009, 12:23 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Your class wewn (funny name) is local to the constructor of the outer class, just like a local variable: it's gone when your constructor terminates; you don't create an object of that class in your constructor so it's basically a waste of space.
kind regards,
Jos
-
kwaspl, you have asked a new question before answering replies in your previous thread/question (Problem with updating JTable), and this will not encourage people to help you here. Why help if you already know that your answer will be ignored? You may wish to fix this.
- 12-21-2009, 02:28 PM #4
Member
- Join Date
- Dec 2009
- Posts
- 4
- Rep Power
- 0
I'm sorry but I'm just so frustrated and no one gives me a strait answer. Maybe i don't explain it well but i create a JTable in one class data to this table are taken from a array. Now in a different window i make some changes to those variables and i can't to make that table to update those variables after i done. I'm working on this problem for three days. Usually i don't look for help.
-
We're not trying to hide anything from you. If you don't understand a particular about anything we have posted, then ask about it. But in the very least at least acknowledge that you have read a reply and appreciate any effort made in posting it, whether or not you understand it.
Your best bet may be to create and post an SSCCE (see the link as it will explain all).Maybe i don't explain it well but i create a JTable in one class data to this table are taken from a array. Now in a different window i make some changes to those variables and i can't to make that table to update those variables after i done. I'm working on this problem for three days. Usually i don't look for help.
Note that much of your problems seem to stem not from Swing issues but from basic Java issues. You may wish to back off from Swing a bit and hit the more basic tutorials first.
Similar Threads
-
Creating a Defined Class with Member Functions
By New2Java in forum New To JavaReplies: 6Last Post: 08-05-2009, 09:05 PM -
How to call defined java class in Jsp
By asheeshiit in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-04-2009, 04:21 AM -
[SOLVED] Accessing private constructor
By piyu.sha in forum New To JavaReplies: 2Last Post: 10-06-2008, 05:45 AM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks