Add and remove columns from JTable
Help me please!
A try to remove column from JTable. It's removed, but when I try to add column in table, then I get all old (removed early) columns + new column....
I completely confused with it.....
Here is my code for remove column:
class DelC implements ActionListener
public void actionPerformed (ActionEvent e )
int [] HowManyColDelete = table.getSelectedColumns();
if (HowManyColDelete.length !=0)
TableColumnModel tableCModel = table.getColumnModel();
for (int i = HowManyColDelete.length-1; i>-1; i--)
table.getColumnModel().removeColumn (tableCModel.getColumn (HowManyColDelete [ i ]));
else
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
}
It's little ex for me, I just try understand clearly how it's work (table models i mean). Here is code. All action with tables take place through menu items.
My brain is boiled, I've try a lot of variants of code, but did't get right result :((
It's code represent problem, which I've describe above. If you'll try remove column and then add it again, it will be ma-a-a-any colunms...
I understand, that my code just hide columns, not delete from table model....
But now I have not any decision of my problem...
Thanks a lot for any help. :)
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.table.DefaultTableModel;
class JTableF extends JFrame
Object [] [] data = new Object [0] [2];
JTable table;
DefaultTableModel model;
String [] columnNames = {"1", "2"};
TableColumnModel cm;
JTableF()
super("Table features");
setDefaultLookAndFeelDecorated( true );
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar MBar = new JMenuBar();
JMenu [] menus = {new JMenu("A"), new JMenu("B")};
JMenuItem [] menu1 = {new JMenuItem("Add row"), new JMenuItem("Delete row", 'D'), new JMenuItem("Add column"), new JMenuItem("Delete column")};
menu1 [ 0 ].addActionListener(new AddL());
menu1 [ 1 ].addActionListener(new DelL());
menu1 [ 2 ].addActionListener(new AddC());
menu1 [ 3 ].addActionListener(new DelC());
for (int i=0; i<menu1.length; i++)
menus [ 0 ].add( menu1 [ i ]);
for (int i=0; i<menus.length; i++)
MBar.add(menus );
JPanel panel = new JPanel ();
model = new DefaultTableModel( data, columnNames );
table = new JTable (model);
cm = table.getColumnModel();
panel.add (new JScrollPane(table));
JButton b = new JButton ("Add row button");
b.addActionListener(new AddL());
panel.add (b);
setJMenuBar (MBar);
getContentPane().add(panel);
pack();
setLocationRelativeTo (null);
setVisible (true);
class DelC implements ActionListener
public void actionPerformed (ActionEvent e )
int [] HowManyColDelete = table.getSelectedColumns();
if (HowManyColDelete.length !=0)
TableColumnModel tableCModel = table.getColumnModel();
for (int i = HowManyColDelete.length-1; i>-1; i--)
int vizibleCol = table.convertColumnIndexToView(HowManyColDelete [ i ]);
tableCModel.removeColumn (tableCModel.getColumn (vizibleCol));
//cm = tableCModel;
else
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
class AddC implements ActionListener
public void actionPerformed (ActionEvent e)
//table.setColumnModel(cm);
Object NewColumnName = new String();
NewColumnName = JOptionPane.showInputDialog ("Input new column name", "Here");
int i = model.getRowCount();
int j = model.getColumnCount();
Object [] newData = new Object [ i ];
model.addColumn ( NewColumnName, newData);
class AddL implements ActionListener
public void actionPerformed (ActionEvent e)
int i = model.getColumnCount();
Object [] Row = new Object [ i ];
model.addRow ( Row );
class DelL implements ActionListener
public void actionPerformed (ActionEvent e)
int [] HowManyRowsDelete = table.getSelectedRows();
if (HowManyRowsDelete.length !=0)
for (int k = HowManyRowsDelete.length-1; k>-1; k--)
model.removeRow (HowManyRowsDelete[k]);
else
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Row is not selected!");
public static void main (String [] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
JTableF inst = new JTableF();
Similar Messages
-
Is there any API to add and remove certs from acrobat trusted identities?
Is there any API to add and remove certs from acrobat trusted identities? if this is not possible any work around for this. Please help me
No, there is not – that would be a security concern.
-
How am I able to add and remove people from a group message?
How am I able to add and remove people from a group message?
You'd need to start a new thread.
-
How do I add and remove mp3s from my iPhone?
I've forgotten again how to add and remove mp3s from my iPhone. Can someone please remind me? I am an iTunes subscriber using a PC running Windows 7 and iTunes 11.1.
dj003 wrote:
Where are all these places, and how do I do it, step-by-step? I really have zero understanding at all. I know how to drag-and-drop mp3s onto my Sandisk mp3 player. It's basically one-step. I can't figure out how this is done in iTunes for an iPhone.
Make sure you have iTunes 11.1.1 installed on your computer.
Plug your iPhone into your computer.
Open iTunes. Create a new Playlist and name it whatever you want. I use iPhone Sync.
Go to your Music Library, click and drag the music you want into your new Playlist.
Click on your iPhone along the top right. Click on Music and select Sync Music and choose just the new Playlist.
Click on the Sync button on the bottom right of the iTunes screen. -
Add and Remove Publishers from Replication Monitor using T SQL
Is there any possibility to add an Publishers from Replication Monitor using T SQL.i am trying to configure the replication using T SQL..i can create all other steps but didn't find any way to add publisher to the replication monitor..kindly suggest..
Hi Snehasis,
Tom is correct, there is no T-SQL command to add a publisher to Replication Monitor. However, the server from which you launch Replication Monitor will automatically be added to Replication Monitor if it is a Publisher. Also, you can add additional
Publishers using the Add Publisher dialog.
This is covered in
Add and Remove Publishers from Replication Monitor
Brandon Williams (blog |
linkedin) -
Need to Add and Remove Columns of ADF Read Only table from Backing bean
I have a scenario where I am trying to Populate TransientVO which is shown has a ADF Read Only Table in page.
I have couple of Check Boxes Based on their selection I am trying to render and hide certain Columns.
But the Issue which I am facing is only the Column Header seems to change where as the Rows and Values doesnt..
even If I apply the expression language rendering condition on the outputText inside those columns.. ..
So I am thinking to add and remove VO Attribute columns to the table from backing bean.
Need some sample code snippet or a better design to achieve this. Its kind of urgent too...having an aggressive deadline :(
Please chip in People..
Thanks in Advance .
TKTable Code..
<af:table value="#{bindings.InventoryGridTrans.collectionModel}"
var="row"
rows="#{bindings.InventoryGridTrans.rangeSize}"
emptyText="#{bindings.InventoryGridTrans.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.InventoryGridTrans.rangeSize}"
rowBandingInterval="0" id="t4"
partialTriggers="::sbcSales ::sbcUsage ::cb1">
<af:column sortProperty="Period" sortable="false"
headerText="#{bindings.InventoryGridTrans.hints.Period.label}"
id="c38">
<af:outputText value="#{row.Period}" id="ot33"/>
</af:column>
<af:column sortProperty="Past12SalesCount"
sortable="false"
headerText="#{bindings.InventoryGridTrans.hints.Past12SalesCount.label}"
id="c29"
rendered="#{backingBeanScope.IndexPageBackingBean.onUsage != true and backingBeanScope.IndexPageBackingBean.onSales == true}">
<af:outputText value="#{row.Past12SalesCount}"
id="ot40"
rendered="#{backingBeanScope.IndexPageBackingBean.onUsage != true and backingBeanScope.IndexPageBackingBean.onSales == true}"
visible="#{backingBeanScope.IndexPageBackingBean.onUsage != true and backingBeanScope.IndexPageBackingBean.onSales == true}">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.InventoryGridTrans.hints.Past12SalesCount.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="Past12UsageCount"
sortable="false"
headerText="#{bindings.InventoryGridTrans.hints.Past12UsageCount.label}"
id="c40"
rendered="#{backingBeanScope.IndexPageBackingBean.onUsage == true and backingBeanScope.IndexPageBackingBean.onSales != true}"
visible="#{backingBeanScope.IndexPageBackingBean.onUsage == true and backingBeanScope.IndexPageBackingBean.onSales != true}">
<af:outputText value="#{row.Past12UsageCount}"
id="ot47"
rendered="#{backingBeanScope.IndexPageBackingBean.onUsage == true and backingBeanScope.IndexPageBackingBean.onSales != true}"
visible="#{backingBeanScope.IndexPageBackingBean.onUsage == true and backingBeanScope.IndexPageBackingBean.onSales != true}">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.InventoryGridTrans.hints.Past12UsageCount.format}"/>
</af:outputText>
</af:column>
</af:column>
</af:table> -
How do I add and remove music from iTunes in iPhone?
I've been having trouble with my phone memory (16gb) being used up by music. I recently change setting to have it covert higher bit songs to 128 kbps which seemed to help.
I just converted to new iOs 7 and it started downloading all music from iTunes in my laptop—which overfilled the memory again.
I tried to go to manual sync and now I cannot see how to add or remove any music (and can't see the bar at the botto of the summary page which should tell me how the memory space is being used and what is available.I don't know. It seeme to disappear after I check that I would manually sync.
-
How can I add and remove items from the bookmarks toolbar?
I want to remove items from the bookmarks toolbar and add ones that I use on a regular basis. How can I do this?
See:
*https://developer.mozilla.org/en/Chrome
*http://en.wikipedia.org/wiki/User_interface_chrome#User_interface_and_interaction_design -
VBS Script to add and remove computers from a group
Good Morning everyone I need some help, I need to develop a script with excel vb + to do the following:
I select a group of ad through a comboBox and that in another box I specify the computers, just below dde has 2 buttons to add or remove these computers that were selected.
Thank you for now ...
sorry for my basic englishHi,
We're definitely willing to help, but you need to ask a question first. Please note that we don't write scripts on demand here.
If you're looking to use VB.Net (not VBScript), that forum is this way:
http://social.msdn.microsoft.com/Forums/en-us/home?forum=vbgeneral&filter=alltypes&sort=lastpostdesc
Don't retire TechNet! -
(Don't give up yet - 12,830+ strong and growing) -
How to Add and Remove Apps from Launchpad?
I have noticed that I have apps missing in launchpad that I do have in my apps folder.
How do I add these to launchpad.
On the flip side, then how can I remove apps from launchpad that I hardly ever use?Did you check the second page of Launchpad?
Click the second white dot in the bottom middle of the Launchpad screen.
Hope information from these articles helps.
http://support.apple.com/kb/PH4524
http://www.macobserver.com/tmo/article/how_to_get_the_most_from_the_macs_launchp ad
Best. -
How do I add and remove songs from my iPhone through iTunes.
I'm sure it seems pathetically simple if you know how to do it, but I've just spent too much time trying to figure out how to remove songs from my music player on my iPhone.
Open itunes, connect iphone, select what you want, sync.
iOS: Syncing your data with iTunes - Support - Apple -
Add and Remove DOCTYPE from cXML
Hi,
I'm currently using Message mapping from cXML to idoc and vice versa. I need a remove the DOCTYPE declaration on the inbound cXML and add DOCTYPE for outbound. I understand, it is possible to have a JAVA mapping or XSLT to resolve this problem, since i'm not expert in Java. Can someone send me a Java code which could help me resolve this issue. Any ideas or help is greatly appreciated.
Thanks!.Hi Ganesh,
i think most easy would be ABAP:
Do not parse the message, just call a fm to convert to string:
DATA:
* xml message
l_message TYPE string.
*create a string to search (and replace) in it
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
EXPORTING
im_xstring = source
im_encoding = 'UTF-8'
IMPORTING
ex_string = l_message.
Then use the right string operation for example REPLACE:
REPLACE FIRST OCCURRENCES OF
'<!DOCTYPE...'
IN
l_message
WITH
Finally switch back to XString:
* create a XString: Ready, no use of DOM!
CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'
EXPORTING
im_string = l_message
im_encoding = 'UTF-8'
IMPORTING
ex_xstring = result.
Regards,
Udo -
Remotely add and remove Instances from different pages
Similar to my other post, I have a form that has multiple pages, one being a calculator (OA_CALC) that shows every variable for calculation; the second (OA_PG1), customer facing showing only pertinent information. So both tables should add/remove and show the data being contolled from OA_CALC. I am able to addInstance and source the date to both pages, but for some reason removeInstance only works on the page where the button exists. So rows on OA_PG1 never delete, please advise.
On OA_CALC i have an ADD ROW button with the following code:
form1.OA_CALC.Table1.HeaderRow.#subform[0].AddRow::click - (JavaScript, client)
OA_CALC.Table1.RowItems.instanceManager.addInstance(1);
OA_PG1.ProjectSavingsGROUP.Table1.RowItems.instanceManager.addInstance(1);
and a DELETE ROW with the following code:
form1.OA_CALC.Table1.RowItems.#subform[0].DelRow::click - (JavaScript, client)
var vIndex = this.parent.parent.index;
OA_CALC.Table1.RowItems.instanceManager.removeInstance(vIndex);
OA_PG1.ProjectSavingsGROUP.Table1.RowItems.instanceManager.removeInstance(vIndex);
One thing that I tried was creating buttons on OA_PG1 with the code specific to that table, that seemed to work. So I know the syntax works, but cannot figure out how to control it from a different page. Please help.
Thanksurgh, apparently I am still very close. I have used your sample, but it seems that the execEvent("click") is not working correctly or my syntax is wrong somewhere. Where am I going wrong?
Button Code on first table:
form1.OA_CALC.Table1.RowItems.deleteBtn::click - (JavaScript, client)
var vCurrentRow = this.parent.index;
OA_CALC.Table1._RowItems.removeInstance(vCurrentRow);
xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]").deleteBtn.execEvent("click");
Invisible Button Code on second table:
form1.OA_PG1.ProjectSavingsGROUP.Table1.RowItems.deleteBtn::click - (JavaScript, client)
OA_PG1.ProjectSavingsGROUP.Table1._RowItems.removeInstance(this.parent.index);
Edit: Here is the Console report from the Acrobat JavaScript Debugger:
xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]") is null
7:XFA:form1[0]:OA_CALC[0]:Table1[0]:RowItems[1]:deleteBtn[0]:clickException in line 7 of function top_level, script XFA:form1[0]:OA_CALC[0]:Table1[0]:RowItems[1]:deleteBtn[0]:click
TypeError: xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]") is null
7:XFA:form1[0]:OA_CALC[0]:Table1[0]:RowItems[1]:deleteBtn[0]:click -
How to add and remove storage from ASM at the same time?
Scenario:
I want to drop some disks from asm
1- Add disk to asm -----> rebalance
2- drop disk from asm ----> rebalance
Is there anyway to make this process faster instead of going to rebalancing twice?I think you could try something like this.....
Add with a power limit of zero and then drop the disks with a powerlimit of 11.
alter system set ASM_POWER_LIMIT=0;
select * from v$asm_operation;
alter diskgroup DBFILE01_GRP
add disk 'ORCL:DB0009', 'ORCL:DB0010', 'ORCL:DB0011', 'ORCL:DB0012';
alter diskgroup DBFILE01_GRP drop disk DB0001, DB0002, DB0003, DB0004;
alter diskgroup DBFILE01_GRP rebalance power 11;
select * from v$asm_operation; -
How do I add and remove icons from my Mac Air desktop?
i downloaded Abode Acrobat and it left an icon on my Mac Air desktop. I would like to remove it. Also, how do I put an icon on the desktop for ready reference later?
1. Drag the icon to the Trash.
2. Drag the icons there, with or without pressing the Option and Command keys while dragging.
(69094)
Maybe you are looking for
-
Motorola SLVR L7 and iSync - or sync to an internet server...
Just bought it yesterday, surprised that it is not supported by iSync. I've got the latest OS X version, iSync version. Worked great with my RAZR, what is the timing for SLVR? How long do I have to keep the phone in the box before it is useful to me?
-
Parallels 9, XP, & OS X Mavericks - can't boot into Parallels anymore
I posted this in the wrong forum...reposting on the suggestion that this is the correct location.... I have Parallels 9.0.24251. I boot into XP. I was able to run Parallels 9 (yes very slowly) until the other week when I upgrade OS X. I was on the
-
After connecting mac pro to tv, how to view movie on tv from laptop
After I connect my Mac Pro to my tv, how do I view a movie on tv coming from my laptop ?
-
E7-00 contact edit: not possible to paste a phone ...
Gentlemen, As said in the topic, it's not possible to paste a phone number together with the + sign in front of the country code. Instead you need to add + manually and paste the rest of the number. It means that when selecting the phone number text
-
SUS user data not replicated to SRM
In service SRMSUS in the SUS system, we have user w/ role SAP_EC_SUS_ADMIN_VENDOR. When this user modifies his own user data such as name/email/time zone, the change in user data is NOT replicated to the SRM system. The SRM user data still contains