The Artima Developer Community
Sponsored Link

Java Answers Forum
Could anyone help me: table staff?

3 replies on 1 page. Most recent reply: May 18, 2004 6:52 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Mike Lee

Posts: 3
Nickname: mike2004
Registered: May, 2004

Could anyone help me: table staff? Posted: May 11, 2004 10:12 PM
Reply to this message Reply
Advertisement
I have difficulty adding a table to a frame.That frame has got buttons, textarea etc,and the frame is in a class which is inherited from Frame. Now my question is: How can I add a table to that frame to replace that textarea? Do I need to put all the code for creating that table in a separate class or put those code into the class in which that frame is ? I am using Jtable, but not sucessful. Thank you very much.


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Could anyone help me: table staff? Posted: May 12, 2004 12:37 AM
Reply to this message Reply
My tip: forget the Text-Area.

Use a JScrollPane , then assign the JTable to the Scrollpane using

jSPan_myPanel.setViewportView(jtab_myTable);


You can leave the code in your frame.

Mike Lee

Posts: 3
Nickname: mike2004
Registered: May, 2004

Re: Could anyone help me: table staff? Posted: May 13, 2004 12:58 AM
Reply to this message Reply
Thank you very much for your reply.I would like to ask you some questions(Sorry, I am new to java).

Actually, my case is :
I've got a class :

class AllComponents extends Frame{
//this class creates all components in a frame: buttons, textarea , etc.
...

lower_panel.add(text_area, "Center");
//This statement is for creating a textarea with some text.If I comment out this statement, the textarea will disappear.
...



}


I've got another class which creates a table:

class SimpleTable extends JFrame
{
public SimpleTable()
{
table = new JTable(dataValues,columnNames);
...

}


public static void main(string args())
{
SimpleTable thisFrame = new SimpleTable();
thisFrame.setVisible(ture);
}

}

When I run SimpleTable as a standalone one,it produces a table for me. Now I want to add this table to the class AllComponents to replace that textarea, so when I run AllComponents, I will see a talbe instead of that textarea.

so my questions are: How can I insert the class SimpleTable to class ALLComponents?(I Know I need to get rid of main().)
Does it matter that SimpleTable extends JFrame but AllComponents extends Frame?
Can I comment out lower_panel.add(text_area, "Center"), add a new statement lower_panel.add(mytable, "Center")?

Will appreciate anyone's help.

Mike

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Could anyone help me: table staff? Posted: May 18, 2004 6:52 AM
Reply to this message Reply
Hope this helps.
You really have a lot of possibilities to do this, I hope this gives you an impression how many there are.

You could exchange
public ALLComponents (JComponent cmp) {
with
public ALLComponents (JTable tab) {
to avoid that anything else then a JTable can be put to lower_panel.



class ALLComponents extends JFrame {
/** puts a text-area in the center of lower_panel
*/
public ALLComponents () {
this (new JTextArea());
//put all the code in the other constructor, so you don't have to write it twice.
}

/** puts a component in the middle of center panel
*/
public ALLComponents (JComponent cmp) {
//lower_panel = ...
lower_panel.add(cmp, "Center");
}

public static void main (String[]args) {
ALLComponents allC = new ALLComponents();
allC.show();
}
}

//SimpleTable should not extend JFrame, since you don't want to use this class as frame, but instead you want to create a ALLComponents object

class SimpleTable {
public static void main (String[] args) {
ALLComponents allC = new ALLComponents(new JTable(dataValues, columnNames));
allC.show();
}
}

//this would be another nice way to do it:
class SimpleTable2 extends ALLComponents {
public SimpleTable2 () {
super(new JTable(dataValues, columnNames));
}
public static void main (String[] args) {
SimpleTable2 sim = new SimpleTable2();
sim.show();
}
}


Flat View: This topic has 3 replies on 1 page
Topic: Reversing Order of Words in a Sentence Previous Topic   Next Topic Topic: PHP Developer wants to learn Java platform

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use