Posts

How to add dynamically rows number in jTable - Java

Most of the programming now a days required dynamically create controller such as button, textbox and also table. Today i want to show how to dynamically set rows number in jTable Swing Controls. Firstly is to set the DefaultTableModel and assign to jTable. Here is the example : The DefaultTableModel import javax.swing.table.DefaultTableModel;   : : String colNames[] = {"Name", "Edit", "View"};  DefaultTableModel dtm = new DefaultTableModel(null,colNames);  Do looping to add rows in jTable for(int i=0; i < listOfString .size();i++){             dtm.addRow(new String[3]); } Assign to jTable  jTable2.setModel(dtm); The full Code :  String colNames[] = {"Name", "Edit", "View"};   DefaultTableModel dtm = new DefaultTableModel(null,colNames);  List<String> listOfString = new ArrayList<>();         listOfString.add("1");         listOfString.add("2");         listOfString.add("3");      

How to add button in JTable - Java

Image
How to works with JTable in java and want to insert button in the JTable column. Let say you want to add button in JTable column like in this pic :    First step is to get the column of the button and set the CellRenderer for the column :  jTable2.getColumn("Edit").setCellRenderer(new ButtonRenderer());  jTable2.getColumn("Edit").setCellEditor(new ButtonEditor(new JCheckBox()));              jTable2.getColumn("View").setCellRenderer(new ButtonRenderer());  jTable2.getColumn("View").setCellEditor(new ButtonEditor(new JCheckBox())); The Class ButtonRenderer import java.awt.Component; import javax.swing.JButton; import javax.swing.JTable; import javax.swing.UIManager; import javax.swing.table.TableCellRenderer; /**  *  * @author hp1  */ public class ButtonRenderer extends JButton implements TableCellRenderer {     public ButtonRenderer() {         setOpaque(true);     }     @Override     public Component getTableCellRendererComponent(JTable table, O

Using SqlBulkCopy in c#

SqlBulkCopy is a powerful tools that allowed you to update/ insert/ or delete table in database with a batch update. SqlBulkCopy class offer you to load data source as long as the data can be loaded as DataTable or read with iDataReader . Using SqlBulkCopy you can perform : Single update / insert /  delete operation into database; Multiple update / insert /  delete operation into database; Bulk Copy operation with transaction.  This tutorial only show single update / insert / delete operation using sql bulk copy . The C# Method Code using SqlBulkCopy         public void InsertUsingSqlBulkCopy(DataTable tableToUpdate, string tableName, ref string err)         {             using (SqlBulkCopy bulkCopy = new SqlBulkCopy(Configuration.LocalDatabaseConnectionString))             {                 bulkCopy.DestinationTableName = "dbo." + tableName;                 try                 {                     // Write from the source to the destination.                     bulkCopy.Wri

Convert Type to SqlDataType and SqlDataType to Type C#

Type conversion basically involve casting and convert from one type to another. You can try the Type conversion by following this web site . Today i want to share code to convert from Type to SqlDataType. This method can be used for example to add parameters to SqlCommand based on DataTable column DataType, see example below : SqlCommand dbComm = new SqlCommand("<sql statement>",<sql connection>); dbComm.Parameters.Add("<parameter name>", < sql Data Type>]).Value  = "test"; what about if you have DataTable and you want to automatically loop into column of datatable and and automatically assign Sql Data Type based on Column DataType of data table ..?There is nothing method or casting that available to do this, but after i googling about converting / casting DataType to SqlDataType, the result seem like impossible to done in .net . C# Parse SqlDbType Convertion C# data types to SQL Server data types   Convert DataColumn.DataType to Sq

Modal Popup Message Box ASP.NEt C# Example

Image
Message box is a must in a web application right now. I will show example how to create message box like picture above. Requirement to try this example : AjaxControl Toolkit User Control  :  MessageBox.ascx Sample Page To call Message Box : MessageModalPopup.aspx The MessageBox.ascx  <link href="../messageBoxStyle.css" type="text/css" rel="Stylesheet" /> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <asp:ModalPopupExtender BackgroundCssClass="modalBackground" ID="ModalPopupExtender1"     Drag="true" DropShadow="true" PopupControlID="Panel1" TargetControlID="Button2"     runat="server"> </asp:ModalPopupExtender> <asp:Button ID="Button2" runat="server" Text="Button" Style="display: none;" /> <asp:Panel ID="Panel1" runat="server

Auto Complete Example ASP.NET AjaxToolkit C#

Image
Auto complete is one powerful feature in modern web application. It is helping people to get the suggestion what are the word to put in the textbox. Today i want to show example how to use AutoComplete feature in AjaxToolkit Asp.Net The List of requirement : AjaxToolkit library AutoCompleteTextBox.aspx Page DataAutoComplete.asmx Web services The AutoCompleteTextBox.aspx Page :  <%--Script Manager--%>     <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">     </asp:ToolkitScriptManager>     <%--The Textbox--%>     <asp:TextBox ID="TextBox1" runat="server" Width="259px"></asp:TextBox>     <%--Auto Complete Textbox Extender Controller--%>     <asp:AutoCompleteExtender ID="autoComplete1" runat="server" EnableCaching="true"         BehaviorID="Auto" MinimumPrefixLength="2" TargetControlID="TextBox1"         ServicePath=&

How to create zip file to download in JSP- Servlet

Image
Hye, my previous post show that how to download zip file in ASP.NET ,. In this tutorial i will show the same thing, but in Jsp-Servlet. Note : In this tutorial i will use this library :- JSTL 1.1  The JSP File  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">         <title>Download File As ZIP File</title>     </head>     <body>        <h1>Download File As ZIP File</h1>         ${DownloadMessage}         <br/>         <form action="<c:url value="/downloadFileServletZip" />" method="post" >             Default Path is server to download is D:\JAVA\dist\Output\             <input type="submit" name="bDownload"