Putting a combobox in an advanceddatagrid
I know that I was able to do this in Flex 3, but for some reason I keep getting errors in Flex 4 by trying to put a ComboBox into an advancedDataGrid. I basically want the datagrid to be completely independent of the list of objects that are in the datagrids dataProvider.
Right now I have something that looks like this:
<ns:XX_DataGrid id="serversDataGrid" left="3" right="3" bottom="4" allowMultipleSelection="false" selectable="false" dataProvider="{dModel.serversSelectedForDeployment}">
<ns:groupedColumns>
<ns:XX_DataGridColumn headerText="{l.Servers_ServiceTag}" dataField="SvcTag" width="118" sortCompareFunction="onSvcTagSort"/>
<ns:XX_DataGridColumn headerText="{l.Servers_Model}" dataField="Model" width="110" sortCompareFunction="onModelSort"/>
<mx:XX_DataGridColumn headerText="{l.Profile}"
itemRenderer="com.dell.pg.spectre.components.itemRenderers.ComboBoxItemRenderer"
/>
</ns:groupedColumns>
</ns:XX_DataGrid>
The item renderer looks like this:
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<s:Label text="{data}"/>
</s:MXDataGridItemRenderer>
I've tried this several ways. Anyone know how to get this to work?
Your renderer should have a combobox instead of the label.
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<s:Label text="{data}"/> - here you need the combobox and will have to override the set data method.
</s:MXDataGridItemRenderer>
Similar Messages
-
How can I put more than One ComboBox in the Driving Frame of a Frame Driver
Hi,
I am working with a Frame Driver and I want that in the Driving Frame put more than one ComboBox to filter the report, for example, I want to put one combobox for City, another for Year, and another for Month, and when the user select the City, Year and Month and do click in Submit button, then in the Target Frame appears the information for those filters.
Does anybody know how to do that?
Thanks a lot.
Bye,Hi,
It is not possible to have more than one combo in the source frame. This is because frame drivers can take only
two columns in the sql query, one is the display value and the other the return value.
Thanks,
Sharmila -
Hi all,
How can I put a comboBox inside a datagrid?
I want to set the comboBox with their own dataprovider and
the id should
pass to the datagrid fill at the save time.
I try this but doesnt let me to include a dataprovider.
Any links??
please help and thank you in advance.
JFB
<mx:DataGridColumn headerText="Rate" dataField="rate"
editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:VBox>
<mx:ComboBox id="rate_cb"></mx:ComboBox>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>Hi,
I think you need to declared your array public at the
begining of the page
like
[Bindable]
public var dataArray = new ArrayCollection();
You need to use outerDocument.
<mx:ComboBox activate="true" labelField="TEXT"
dataProvider="{outerDocument.dataArray}" />
I discover that the components are case sensitive also.
I hope this help.
JFB
"MLK_SS" <[email protected]> wrote in
message
news:[email protected]...
> Hi All,
>
> I am having a problem displaying data into a combo box
inside a data grid.
>
> I am getting data from a webservice and storing the data
into a Array
> Collection variable and trying to pass the var as the
data provider for
> the
> combo box.
>
> If I try an individual combo box it works fine.
>
> But, when trying to integrate into a datagrid it gives
an error saying
> Access
> of undefined property. I tried using outerDocument as
mentioned above, the
> error doesnot show up but the output does not show up
with the data inside
> the
> Data grid Combo box.
>
> <mx:DataGrid id="fav" x="10" y="332"
headerColors="[#C3D3AA, #C3D3AA]"
> enabled="true" editable="true"
textDecoration="underline">
> <mx:columns>
> <mx:DataGridColumn width="120" headerWordWrap="true"
> headerText="Fav./Del./ Copy/Edit" fontWeight="bold"
editable="false"
> dataTipField="Favourites" activate="true" >
> <mx:itemRenderer>
> <mx:Component>
> <mx:VBox>
> <mx:ComboBox activate="true" labelField="TEXT"
> dataProvider="{dataArray}" />
>
> </mx:VBox>
>
> </mx:Component>
> </mx:itemRenderer>
> </mx:DataGridColumn>
> </mx:columns>
> </mx:DataGrid>
>
> the function that handles the data result is :
>
> public function handleResult(event:ResultEvent):void{
>
> dataArray = new ArrayCollection();
>
> tasktypeArray = new ArrayCollection();
> var myXML:XML = new XML(event.result);
> var kf:XMLList = myXML.child("WORKLIST");
>
> var tasktype:XMLList = myXML.child("TASKTYPE");
> a = kf.item;
> b= kf.item[0].TEXT;
>
> textarea1.text = myXML.toXMLString();
> textarea3.text = myXML.child("TEMPLATE");
> trace(kf.child("TEXT").length());
> for (var x:int = 0; x < 25; x++) {
> var resultObj:Object = new Object ();
>
> resultObj.TEXT
> =tasktype.descendants("item")[x].TEXT.valueOf();
> dataArray.addItem(resultObj);
>
> }
>
> Please let me know where I am going wrong
>
> Thanks,
>
> -
Dear Sir;
how can put a combobox that is linked to a table in a matrix that is linked to another table?
thank you Dear.Hi Dany,
To do that you just have to do:
1 -Create the combo´s valid values table (@Values)
2 -Createa a UDF in at line level, and link it to the table @Values.
The link is made using the Code field of the UDT.
This will do the trick.
Regards,
Ibai Peñ -
How to have a combobox in JTable column header?
Any simple ways for doing this? I am trying to get a filter to a JTable, so that only the rows containing the selected value in that column would be shown.
I first need to get this combobox into the header of a column.Thanks.
I have already tried with this way, but it was too long and complicated to implement into my file.
Could someone post the principles here.
Like this:
// create my combobox
JComboBox myBox = new JComboBox();
myBox.addItem("Cat");
myBox.addItem("Dog");
// put the combobox to column header
??? ANY CODE HERE ???
Tnx ahead!
OK!
AUlo -
About dropbox and combobox widgets and variables
This is a two-part problem.
First, I wanted to use a combo box (or drop box) widget to insert a field that can be populated by choosing one of six options (A through F). The variable that gets populated is called 'a'. On the slide, there is the drop (or combo) box and a button that executes an advanced action. In the advanced action, It goes:
IF variable 'a' is equal to 'A' go to slide x.
ELSE go to slide y.
No matter what option is chosen on the combo (or drop) box, nothing gets assigned into the variable. I tried this with both widgets. I finally ended up using a textbox and asking the user to type the correct option into the text box.
Which leads me to the secont part of the problem. The textbox is associated to the variable 'a'. The correct answer is 'A'. The advanced action is the same as above. However, if I want to make the correct answer lower-case 'a', the advanced action ALWAYS evaluates as false and executes the 'ELSE' action, even if the user enters lower-case 'a' into the field. Regardless of what is entered as the answer in this text field, I simply cannot get a correct answer. Meanwhile, if the advanced action is changed to accept the upper-case 'A' as the correct answer, it works.
What am I doing wrong here? What do I need to do to make use of the combo box (or drop-box) widgets in the first place? Anyone with more experience?Thanks for the response. it's Captivate 5 (sorry for forgetting).
I went ahead and renamed my variables to something more meaningful. That didn't quite resolve the problem. I went ahead with further investigation. I put five comboboxes, each with six different values and each populating their own variables. To see what's actually being entered into those variables, I put a simple text box on the side and populated it with variable values. My advanced action looked at those variables and and executed one of the two specific actions, depending on what the variables contained ("IF [variables] EQUAL TO [a set of data], then do this; ELSE do that"). However, no matter what they contained, it continued to execute the 'Fail' action, rather than 'Correct'. After a while, I noticed in that textbox that showed variable content, that there was a small space before the text. The space did NOT appear if I chose the first option on the list. This led me to see if the combobox would work if I listed options without any spaces. My original entry was: First, Second, Third, Fourth, Fifth. I changed the entry to: First,Second,Third,Fourth,Fifth. This finally solved my problem!
It seems that the widgets that come with Captivate don't behave consistently. Checkbox widget works properly when options are entered with spaces after commas. Combobox doesn't seem to. I haven't tested dropbox yet (I'm in a rush to deliver), but my guess is it won't allow spaces either.
One way to resolve this would have probably been to modify the action to say: IF [variable] CONTAINS [literal]..., instead of: IF [variable] IS EQUAL TO [literal]...
So, this problem has now been resolved. However, I now have a weird problem that I can't figure out, and it looks like a Captivate 5 bug. I have some 15 advanced actions. For some reason, I can no longer select one of them (no. 7 or so). All others I can select and edit, but this particular one I can't recall at all. The action no longer works correctly, so I re-created it, called it something else, and am now calling this new one. The original one can't be edited or deleted, and I'm just a bit concerned what's happened with that script.
Has anyone encountered this situation before? -
ComboBox screws up mouse events
I'm having a problem where after selecting something from a
comboBox, the
mouse events sent to buttons and movieClips (that have
nothing to do with
the comboBox) no longer work correctly.
After using the comboBox, if you click on a button or
movieClip, without
moving the mouse, the button or movieClip no longer receives
mouse events
until the mouse is moved.
This is most noticable with something like a "Next" button,
that is clicked
repeatedly without moving the mouse. The first click will
work, then other
clicks will stop working (as well as rollOver). If you move
the mouse just
one pixel over, then it works again.
This is easily reproduced in a test fla. Create a button that
traces
"press" and "release". Put a comboBox on the stage with a few
items and be
sure to name the comboBox instance.
Has anyone experienced this and has a workaround. The only
workaround I
have found is to not use comboBox..OK, I still think this is a bug, but I've found a workaround:
The problem is that the comboBox contains an input text
field, and even if
you have the comboBox's editable property set to false, the
input text field
gets FOCUS when you click on the comboBox. Then when you go
and click on
the button, the input text field still has focus, and not the
button. Why
the button stops working after the first click and release is
what seems
like a bug. The button does not have focus and clicking on it
doesn't give
it focus. You can see the same thing if you put an input text
field on the
stage, play the movie and click in the text field. Even
though you are
clicking on the button, the i-beam is still blinking in the
text box, and
you will see the same messed up functionallity that I
originally described.
Here is the workaround. You have to explicitly give the
button focus.
_focusrect = false; // don't want yellow box around item in
focus
test_btn.onPress = function() {
trace("press");
focusManager.setFocus(this); // this sets focus back to the
button
test_btn.onRelease = function() {
trace("release");
Chris
"Chris" <[email protected]> wrote in message
news:[email protected]...
> I'm having a problem where after selecting something
from a comboBox, the
> mouse events sent to buttons and movieClips (that have
nothing to do with
> the comboBox) no longer work correctly.
>
> After using the comboBox, if you click on a button or
movieClip, without
> moving the mouse, the button or movieClip no longer
receives mouse events
> until the mouse is moved.
>
> This is most noticable with something like a "Next"
button, that is
> clicked
> repeatedly without moving the mouse. The first click
will work, then
> other
> clicks will stop working (as well as rollOver). If you
move the mouse
> just
> one pixel over, then it works again.
>
> This is easily reproduced in a test fla. Create a button
that traces
> "press" and "release". Put a comboBox on the stage with
a few items and
> be sure to name the comboBox instance.
>
> Has anyone experienced this and has a workaround. The
only workaround I
> have found is to not use comboBox..
>
>
> -
I'm using a spark combobox in my AdvancedDataGrid, as an itemEditor. At some point I noticed that clicking on the scroll bar arrows would close the CB - very annoying. After much research I found this which completely solved my problems - awesome!
One more and last lingering issue left though: when selecting an item from an open dropdownlist the mouse click seems to propagate to the cell below once the dropdown has closed. I assumed that the fix above would take care of this last issue, but it doesn't seem to. I tried to override the item_mouseDownHandler for the CB and stopImmediatePropagation() of the mouse event post its usual behavior, but that also seems to have no effect. I also tried setting the mouseChildren property for the skin['dropDown'] to false, but that impairs the whole functionality.
Would love any help / suggestions.
thank you all, as always
fI'm not sure. Happy to try this out and post code if it helps debugging the issue, but I'm stuck with an ADG, so switching to DG would not be an option for me.
-
ComboBox / DropDown with UIX
Hello People,
I'm bulding an application using Business Components and UIX JSP for BC, how can I put a ComboBox or a DropDown Control that contains all the information of an attribute of a table.
regards>
I use the messageChoice element and works fine for me. But for it works we must to define the bc4j:viewObjectDef element into bc4j:registryDef element, is it correct?
Yes, you do need the viewObjectDef in the registryDef.
>
Well, if it is, we must to put two parameters into bc4j:registryDef element that are the name of the view and the rangeSize of the view. The rangeSize determines the amount of records to fetch, is it correct? If it is, how can I fetch all records?
I believe that the rangeSize parameter is optional and that omitting it means "return me all rows". Try leaving it off and see if that returns everything.
-brian
Team UIX -
HI all,
I have a basic proplem! I want to know if I can change the ITEMs in system forms' comboboxes(for example: summary type combobox in order form).
If it is possible please show me the way.
best regards.Hi,
Unfortunately this is not possible.
You would have to use workarounds for that:
Put a ComboBox in exactly that place and e.g. move the original "out of sight"
+ handle tabbing / tab order
+ select values in the original combo appropriately when a value in your combo is selected (there may be no solution what to do in case you add new valid values...)
+ set affects form mode appropriately for the combos...
HTH,
Frank -
What is wrong with the ComboBox?
What a nice Saturday it is...
Why oh why won't a ComboBox show its selection when it's
loaded in a parent movie? Do we have the same issue here as with
the AS2 version? I tried putting a ComboBox in the parent but that
doesn't work either.
Functions as expected when I test the movie with the
ComboBox, when I load that movie in a parent... no text on the
ComboBox. The dropdown works ok, but once you have made a selection
and the ComboBox closes again... no text. Anyone experienced
this?it wouldn't matter whether the cb was added to the stage or
using a.s. it would matter if you picked a unique instance name or
not.
with a non-unique name, the cb appears to be working but
displays no text when closed. if you click the cb and open it,
you'll see the text so you can make different selections. but if
you click a selection, no text appears in the closed cb. -
Hi,
I'm using a ComboBox that pulls down over a MovieClip which
has functions for the onMouseDown and onMouseMove events assigned
to them. Also, the function onMouseDown and onMouseMove is because
i draw a fill rectangle in a MC called canvas_mc. Its a example
that appears on "onMouseDown" help on flash 8. The code on the end.
The problem I am having is when a dropdown event occurs the
list drop of a combobox is over a MC "canvas_mc" and when i select
a item of the combobox, the events onMouseDown occours, well i try
to put the combobox on a MC and then with hitTest function know if
the combobox is over the "canvas_mc" movieclip but doesn't work.
Any idea???
Thanks!!!Try adding this to the onMouseDown listener function.
mouseListener.onMouseDown = function() {
if (canvas_mc.hitTest(_xmouse, _ymouse)) {
this.isDrawing = true;
this.orig_x = _xmouse;
this.orig_y = _ymouse;
this.target_mc = canvas_mc.createEmptyMovieClip("",
canvas_mc.getNextHighestDepth());
This will still execute when the mouse is down but the
drawing will only start if the mouse is down over the canvas_mc
movieClip.
Tim -
Problem in using bar ??
Hi to all friends here ,
i made a bar the i put on it some buttons and i put also comboBox but when i put comboBox the comboBox take all the space that rest in the bar ...
so i decide to put the comboBox on label then put the label on bar
but unfortuantly the label not appear ...
I want to know the correct way for codeing this ...
Here is my code:-
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
public class BarTest extends JFrame {
private JMenuBar barIcon = new JMenuBar();
private final JLabel labelsizeComboBox;
private final JComboBox sizeComboBox;
private final JButton[] buttons;
private String[] images = {"new.JPG", "open.JPG", "save.JPG", "copy.JPG", "paste.JPG"};
private String[] imageName = {"new", "open", "save", "copy", "paste"};
private final ImageIcon[] imagicons;
public BarTest() {
barIcon = new JMenuBar();
labelsizeComboBox = new JLabel();
sizeComboBox = new JComboBox();
for (int i = 6; i < 72; i += 4) {
sizeComboBox.addItem(i);
labelsizeComboBox.add(sizeComboBox);
barIcon.add(labelsizeComboBox);
buttons = new JButton[images.length];
imagicons = new ImageIcon[images.length];
for (int i = 0; i < images.length; ++i) {
imagicons[i] = new ImageIcon(getClass().getResource(images));
buttons[i] = new JButton();
buttons[i].setIcon(imagicons[i]);
buttons[i].setText(imageName[i]);
buttons[i].setToolTipText(imageName[i]);
barIcon.add(buttons[i]);
getContentPane().add(barIcon, BorderLayout.NORTH);
public static void main(String[] args) {
BarTest bar = new BarTest();
bar.setDefaultCloseOperation(BarTest.EXIT_ON_CLOSE);
bar.setSize(500, 250);
bar.setVisible(true);
bar.setLocationRelativeTo(null);
thanks in advance...
Beshoy .A.WHi
This is the final code we wrote it
public BarTest() {
barIcon = new JMenuBar();
sizeComboBox = new JComboBox();
for (int i = 6; i < 72; i += 4) {
sizeComboBox.addItem(i);
barIcon.add(Box.createHorizontalGlue());
buttons = new JButton[images.length];
imagicons = new ImageIcon[images.length];
barIcon.add(Box.createHorizontalStrut(10));
for (int i = 0; i < images.length; ++i) {
imagicons[i] = new ImageIcon(getClass().getResource(images));
buttons[i] = new JButton();
buttons[i].setIcon(imagicons[i]);
buttons[i].setText(imageName[i]);
buttons[i].setToolTipText(imageName[i]);
buttonGroup.add(buttons[i]);
barIcon.add(buttons[i]);
barIcon.add(Box.createHorizontalGlue());
barIcon.add(Box.createHorizontalStrut(10));
barIcon.add(sizeComboBox);
barIcon.add(Box.createHorizontalGlue());
getContentPane().add(barIcon, BorderLayout.NORTH);
In this link you can download the output which appear, you will see :
The button new,open,copy.....etc in the center of bar and there is a space and then the comBobox .
I want the buttons begin from the start of the bar
and then there is very very very small space then put comBobox
thanks -
Hi all,
I am trying to figure out how to put a comboBox in my Flash
form and normally I just use something like:
countryList.dataProvider = ["Country1", "Country2",
"Country3", "Country4"];
var listenerObject:Object = new Object();
listenerObject.change = function(evtObj:Object) {
// code placed here executes
// when the event is triggered
trace("Selected Item: "+countryList.selectedItem);
countryList.addEventListener("change",listenerObject);
This will give me the selected item's value which I can chuck
in a variable and send off to my form...
Well that is usually good enough but now I want to have a
Label AND a Value so that when the user does the drop down they see
the Label but I am actually sending the Value. I am messing around
with the Flash Help code and I kind of see how this is working yet
I can not get at the data I need which is the Value not the Label.
my_cb.dataProvider = [{name:"Gary", gender:"male"},
{name:"Susan", gender:"female"}];
my_cb.labelField = "name";
var listenerObject:Object = new Object();
listenerObject.change = function(evtObj:Object) {
// code placed here executes
// when the event is triggered
trace("Selected Item: "+my_cb.selectedItem);
my_cb.addEventListener("change",listenerObject);
Any help on this would be greatly appreciated.> You would think there was something easy to allow for a
label being
> different
> from the variable I'm sending. All I want to do is make
the drop down menu
> say
> "Afghanistan" while I am sending the form data "AF" to
the .php script
> that
> will save the data to a mySQl database. I can easily
send the name of the
> country (Afghanistan) as thats the name of
my_cb.selectedItem. I'm just
> not
> sure why it is so difficult to send the value (AF)
instead. I'm just not
> getting it.
Did you put the code I supplied in the event handler?
var listenerObject:Object = new Object();
listenerObject.change = function(evtObj:Object) {
// code placed here executes
// when the event is triggered
trace("Selected Item Data: "+my_cb.selectedItem.data); //Put
code here
Dan Smith > adobe community expert
http://www.dsmith.tv -
JTable Problem (table does not show rows and columns)
Hi All,
What the table is suppose to do.
- Load information from a database
- put all the values in the first column
- in the second column put combobox (cell editor with numbers 1-12)
- the 3rd column put another combobox for something else
- the 4th column uses checkbox as an edit
The number of rows of the table should be equal to the number of
record from
the database. If not given it default to 20 (poor but ok for this)
The number of columns is 4.
But the table does not show any rows or
column when I put it inside a
JScrollPane (Otherwise it works).
Please help,
thanks in advance.
public class SubjectTable extends JTable {
* Comment for <code>serialVersionUID</code>
private static final long serialVersionUID = 1L;
/** combo for the list of classes */
protected JComboBox classCombo;
/** combo for the list of subjects */
protected JComboBox subjectsCombo;
/** combo for the list of grade */
protected JComboBox gradeCombo;
boolean canResize = false;
boolean canReorder = false;
boolean canSelectRow = false;
boolean canSelectCell = true;
boolean canSelectColumn = true;
// the row height of the table
int rowHeight = 22;
// the height of the table
int height = 200;
// the width of the table
int width = 300;
// the size of the table
Dimension size;
* Parameterless constructor. Class the one of the other constructors
to
* create a table with the a new <code>SubjectTableModel</code>.
public SubjectTable() {
this(new SubjectTableModel());
* Copy constructor to create the table with the given
* <code>SubjectTableModel</code>
* @param tableModel -
* the <code>SubjectTableModel</code> with which to
initialise
* the table.
SubjectTable(SubjectTableModel tableModel) {
setModel(tableModel);
setupTable();
* Function to setup the table's functionality
private void setupTable() {
clear();
// set the row hieght
this.setRowHeight(this.rowHeight);
// set the font size to 12
//TODO this.setFont(Settings.getDefaultFont());
// disble reordering of columns
this.getTableHeader().setReorderingAllowed(this.canReorder);
// disble resing of columns
this.getTableHeader().setResizingAllowed(this.canResize);
// enable the horizontal scrollbar
this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// disable row selection
setRowSelectionAllowed(this.canSelectRow);
// disable column selection
setColumnSelectionAllowed(this.canSelectColumn);
// enable cell selection
setCellSelectionEnabled(this.canSelectCell);
setPreferredScrollableViewportSize(getSize());
TableColumn columns = null;
int cols = getColumnCount();
for (int col = 0; col < cols; col++) {
columns = getColumnModel().getColumn(col);
switch (col) {
case 0:// subject name column
columns.setPreferredWidth(130);
break;
case 1:// grade column
columns.setPreferredWidth(60);
break;
case 2:// class room column
columns.setPreferredWidth(120);
break;
case 3:// select column
columns.setPreferredWidth(65);
break;
} // end switch
}// end for
// set up the cell editors
doGradeColumn();
doClassColumn();
//doSubjectColumn();
* Function to clear the table selection. This selection is different
to
* <code>javax.swing.JTable#clearSelection()</code>. It clears the
user
* input
public void clear() {
for (int row = 0; row < getRowCount(); row++) {
for (int col = 0; col < getColumnCount(); col++) {
if (getColumnName(getColumnCount() - 1).equals("Select")) {
setValueAt(new Boolean(false), row, getColumnCount() - 1);
}// if
}// for col
}// for row
* Function to set the cell renderer for the subjects column. It uses
a
* combobox as a cell editor in the teacher's subjects table.
public void doSubjectColumn() {
TableColumn nameColumn = getColumnModel().getColumn(0);
nameColumn.setCellEditor(new DefaultCellEditor(getSubjectsCombo()));
// set up the celll renderer
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for drop down list");
nameColumn.setCellRenderer(renderer);
// Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = nameColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
((DefaultTableCellRenderer) headerRenderer)
.setToolTipText("Click the Name to see a list of choices");
}// end doSubjectsColumn----------------------------------------------
/** Function to set up the grade combo box. */
public void doGradeColumn() {
TableColumn gradeColumn = getColumnModel().getColumn(1);
gradeColumn.setCellEditor(new DefaultCellEditor(getGradeCombo()));
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for drop down list");
gradeColumn.setCellRenderer(renderer);
// Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = gradeColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
((DefaultTableCellRenderer) headerRenderer)
.setToolTipText("Click the Grade to see a list of choices");
}// end doGradeColumn-------------------------------------------------
* Function to setup the Class room Column of the subjects
public void doClassColumn() {
// set the column for the classroom
TableColumn classColumn = getColumnModel().getColumn(2);
classColumn.setCellEditor(new DefaultCellEditor(getClassCombo()));
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for drop down list");
classColumn.setCellRenderer(renderer);
// Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = classColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
((DefaultTableCellRenderer) headerRenderer)
.setToolTipText("Click the Class to see a list of choices");
}// end doClassColumn--------------------------------------------------
* Function to get the size of the table
* @return Returns the size.
public Dimension getSize() {
if (this.size == null) {
this.size = new Dimension(this.height, this.width);
return this.size;
* Function to set the size of the table
* @param dim
* The size to set.
public void setSize(Dimension dim) {
if (dim != null) {
this.size = dim;
return;
* Function to create/setup the class room comboBox. If the comboBox
is
* <code>null</code> a nwew one is created else the functon returns
the
* function that was returned initially.
* @return Returns the classCombo.
private JComboBox getClassCombo() {
if (this.classCombo == null) {
this.classCombo = new JComboBox();
// fill up the class name combo
ArrayList classRooms = new ArrayList();
try {
//TODO classRooms = Settings.getDatabase().getClassRooms();
for (int i = 0; i < 10; i++) {
String string = new String("Class");
string += i;
if (!classRooms.isEmpty()) {
classRooms.trimToSize();
for (int i = 0; i < classRooms.size(); i++) {
this.classCombo.addItem(classRooms.get(i));
} catch (Exception e) {
e.printStackTrace();
return this.classCombo;
* Function to create/setup the subjects comboBox. If the comboBox is
* <code>null</code> a nwew one is created else the functon returns
the
* function that was returned initially.
* @return Returns the subjectsCombo.
private JComboBox getSubjectsCombo() {
if (this.subjectsCombo == null) {
this.subjectsCombo = new JComboBox();
try {
ArrayList subjects = loadSubjectsFromDatabase();
if (!subjects.isEmpty()) {
Iterator iterator = subjects.iterator();
while (iterator.hasNext()) {
// create a new subject instance
//TODO Subject subct = new Subject();
// typecast to subject
//TODO subct = (Subject) iterator.next();
String name = (String) iterator.next();
// add this subject to the comboBox
//TODO this.subjectsCombo.addItem(subct.getName());
subjectsCombo.addItem(name);
}// end while
}// end if
else {
JOptionPane.showMessageDialog(SubjectTable.this,
"Subjects List Could Not Be Filled");
System.out.println("Subjects List Could Not Be Filled");
} catch (Exception e) {
e.printStackTrace();
return this.subjectsCombo;
* Function to load subjects from the <code>Database</code>
* @return Returns the subjects.
private ArrayList loadSubjectsFromDatabase() {
// list of all the subject that the school does
ArrayList subjects = new ArrayList();
try {
//TODO to be removed later on
for (int i = 0; i < 10; i++) {
String string = new String("Subject");
string += i;
subjects.add(i, string);
// set the school subjects
//TODO subjects = Settings.getDatabase().loadAllSubjects();
} catch (Exception e1) {
e1.printStackTrace();
return subjects;
* Function to create/setup the grade comboBox. If the comboBox is
* <code>null</code> a nwew one is created else the functon returns
the
* function that was returned initially.
* @return Returns the gradeCombo.
private JComboBox getGradeCombo() {
if (this.gradeCombo == null) {
this.gradeCombo = new JComboBox();
// fill with grade 1 to 12
for (int i = 12; i > 0; i--) {
this.gradeCombo.addItem(new Integer(i).toString());
return this.gradeCombo;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
System.out.println("Look and Feel has been set");
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
SubjectTableModel model = new SubjectTableModel();
int cols = model.getColumnCount();
int rows = model.getRowCount();
Object[][] subjects = new Object[rows][cols];
for (int row = 0; row < rows; row++) {
subjects[row][0] = new String("Subjectv ") + row;
}//for
model.setSubjectsList(subjects);
SubjectTable ttest = new SubjectTable(model);
JFrame frame = new JFrame("::Table Example");
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(ttest);
frame.getContentPane().add(scrollPane);
frame.pack();
frame.setVisible(true);
**************************************END
TABLE******************************
----------------------------THE TABLE
MODEL----------------------------------
* Created on 2005/03/21
* SubjectTableModel
package com.school.academic.ui;
import javax.swing.table.AbstractTableModel;
* Class extending the <code>AbstractTableModel</code> for use in
creating the
* <code>Subject</code>s table. In addition to the implemented methods
of
* <code>AbstractTableModel</code> The class creates a model that has
initial
* values - the values have their own <code>getter</code> and
* <code>setter</code> methods - but can still be used for values that
a user
* chooses.
* <p>
* @author Khusta
public class SubjectTableModel extends AbstractTableModel {
* Comment for <code>serialVersionUID</code>
private static final long serialVersionUID = 3257850978324461113L;
/** Column names for the subjects table */
String[] columnNames = { "Subject", "Grade", "Class Room",
"Select" };
/** Array of objects for the subjects table */
Object[][] subjectsList;
private int totalRows = 20;
protected int notEditable = 0;
* Parameterless constructor.
public SubjectTableModel() {
// TODO initialise the list
// add column to the default table model
this.subjectsList = new
Object[getTotalRows()][getColumnNames().length];
* Copy constructor with the <code>subjectList</code> to set
* @param subjects
public SubjectTableModel(Object[][] subjects) {
this(0, null, subjects, 0);
* Copy constructor with the initial number of row for the model
* @param rows -
* the initial rows of the model
* @param cols -
* the initial columns of the model
* @param subjects -
* the initial subjects for the model
* @param edit - the minimum number of columns that must be
uneditable
public SubjectTableModel(int rows, String[] cols, Object[][]
subjects, int edit) {
// set the initial rows
setTotalRows(rows);
// set the column names
setColumnNames(cols);
// set the subjectlist
setSubjectsList(subjects);
//set not editable index
setNotEditable(edit);
* Function to get the total number of columns in the table
* @return int -- the columns in the table
public int getColumnCount() {
if (this.subjectsList == null) {
return 0;
return getColumnNames().length;
* Function to get the total number of rows in the table
* @return int -- the rows in the table
public int getRowCount() {
if (this.subjectsList == null) {
return 0;
return this.subjectsList.length;
* Function to get the name of a column in the table.
* @param col --
* the column to be named
* @return String -- the column in the table
public String getColumnName(int col) {
if (getColumnNames()[col] != null) {
return getColumnNames()[col];
return new String("...");
* Function to get the value of the given row.
* @param row --
* the row of the object.
* @param col --
* the col of the object.
* @return Object -- the value at row, col.
public Object getValueAt(int row, int col) {
return getSubjectsList()[row][col];
* Function to return the data type of the given column.
* @param c --
* the column whose type must be determined.
* @return Class -- the type of the object in this col.
public Class getColumnClass(int c) {
if (getValueAt(0, c) != null) {
return getValueAt(0, c).getClass();
return new String().getClass();
* Function to put a value into a table cell.
* @param value --
* the object that will be put.
* @param row --
* the row that the object will be put.
* @param col --
* the col that the object will be put.
public void setValueAt(Object value, int row, int col) {
* TODO: Have a boolean value to determine whether to clear or
to set.
* if true clear else set.
if (value != null) {
if (getSubjectsList()[0][col] instanceof Integer
&& !(value instanceof Integer)) {
try {
getSubjectsList()[row][col] = new
Integer(value.toString());
fireTableCellUpdated(row, col);
} catch (NumberFormatException e) {
* JOptionPane .showMessageDialog( this., "The \""
+
* getColumnName(col) + "\" column accepts only
values
* between 1 - 12");
return;
System.out.println("Value = " + value.toString());
System.out.println("Column = " + col + " Row = " + row);
// column = Grade or column = Select
switch (col) {
case 2:
try {
// TODO
if (Boolean.getBoolean(value.toString()) == false
&& getValueAt(row, 0) != null
&& getValueAt(row, 1) != null
&& getValueAt(row, 2) != null) {
// subjectsList[row][col + 1] = new
Boolean(true);
System.out.println("2. false - Updated...");
* this.subjectListModel.add(row,
* this.subjectsList[row][0] + new String(" -
") +
* this.subjectsList[row][2]);
} catch (ArrayIndexOutOfBoundsException exception) {
exception.printStackTrace();
break;
case 3:
if (Boolean.getBoolean(value.toString()) == false
&& getValueAt(row, 0) != null
&& getValueAt(row, 1) != null
&& getValueAt(row, 2) != null) {
System.out.println("3. If - Added...");
getSubjectsList()[row][3] = new Boolean(true);
this.subjectListModel.addElement(this.subjectsList[row][0] +
* new String(" - ") + this.subjectsList[row][2]);
// subjectListModel.remove(row);
fireTableCellUpdated(row, col);
fireTableDataChanged();
// this.doDeleteSubject();
} else if (Boolean.getBoolean(value.toString()) ==
true
&& getValueAt(row, 0) != null
&& getValueAt(row, 1) != null
&& getValueAt(row, 2) != null) {
setValueAt("", row, col - 1);
setValueAt("", row, col - 2);
setValueAt("", row, col - 3);
System.out.println("3. Else - Cleared...");
// this.subjectListModel.remove(row);
break;
default:
break;
}// end switch
getSubjectsList()[row][col] = value;
fireTableCellUpdated(row, col);
fireTableDataChanged();
}// end if
}// end
* Function to enable edition for all the columns in the table
* @param row --
* the row that must be enabled.
* @param col --
* the col that must be enabled.
* @return boolean -- indicate whether this cell is editble or
not.
public boolean isCellEditable(int row, int col) {
if (row >= 0
&& (col >= 0 && col <= getNotEditable())) {
return false;
return true;
* Function to get the column names for the model
* @return Returns the columnNames.
public String[] getColumnNames() {
return this.columnNames;
* Function to set the column names for the model
* @param cols
* The columnNames to set.
public void setColumnNames(String[] cols) {
// if the column names are null the default columns are used
if (cols != null) {
this.columnNames = cols;
* Function to get the rows of subjects for the model
* @return Returns the subjectsList.
public Object[][] getSubjectsList() {
if (this.subjectsList == null) {
this.subjectsList = new
Object[getTotalRows()][getColumnNames().length];
return this.subjectsList;
* Function to set the subjects list for the model
* @param subjects
* The subjectsList to set.
public void setSubjectsList(Object[][] subjects) {
// if the subject list is null create a new one
// using default values
if (subjects == null) {
this.subjectsList = new
Object[getTotalRows()][getColumnNames().length];
return;
this.subjectsList = subjects;
* Function to get the total number of rows for the model. <b>NB:
</b> This
* is different to <code>
getRowCount()</code>.<code>totalRows</code>
* is the initial amount of rows that the model must have before
data can be
* added.
* @return Returns the totalRows.
* @see #setTotalRows(int)
public int getTotalRows() {
return this.totalRows;
* Function to set the total rows for the model.
* @param rows
* The totalRows to set.
* @see #getTotalRows()
public void setTotalRows(int rows) {
// if the rows are less than 0 the defaultRows are used
// set getTotalRows
if (rows > 0) {
this.totalRows = rows;
* Function to get the number of columns that is not editble
* @return Returns the notEditable.
public int getNotEditable() {
return this.notEditable;
* Function to set the number of columns that is not editable
* @param notEdit The notEditable to set.
public void setNotEditable(int notEdit) {
if (notEdit < 0) {
notEdit = 0;
this.notEditable = notEdit;
----------------------------END TABLE MODEL----------------------------------I hope you don't expect us to read hundreds of lines of unformatted code? Use the "formatting tags" when you post.
Why are you creating your own TableModel? It looks to me like the DefaultTableModel will store you data. Learn how to use JTable with its DefaultTableModel first. Then if you determine that DefaultTableModel doesn't provide the required functionality you can write your own model.
Maybe you are looking for
-
Expose/dashboard/and spaces all laggy
I may have the answer all ready but i am just checking for other people's opinions i guess. I just installed 10.5 on my g4 and the expose/dashboard/spaces features are all really laggy and not nearly as smooth as on my macbook. I think that it is due
-
I ordered an iphone 6 and it was received with a damaged screen. I immediately called and was told that that since it's still functional to go ahead and activate it and a new one will be sent out with a box to fedex back the damaged one. I asked for
-
Regarding installation and configuring sun cluster 3.2
Can any provide me the correct hardware and software configurations required for two node cluster for acheiving failover. We have A1000 hardware configured with Raid 5. Does this suit our requirement. I want some clarifications on 1) Configuring the
-
How To Know Which Version of Firmware / software i...
Hi, I just bought my E71. How do I know which version of firmware is installed on my phone, and which version of the Realplayer is installed ? Thanks.
-
10.4.6 to Classic: "Connection Failed" Message
Hi. Hope this is the right forum. It think so, as follows: I have one Classic app on my computer that I must use for work, two or three times each month (its a great time billing program). Since going to 10.4.6 (Combo update) a few weeks ago, wheneve