Java - How to create one Jar file instead of jar file with libraries in lib folder in Netbeans.7/11/2014 If you want to create one Jar file instead of Jar file with libraries in lib folder in Netbeans you can make it with very simple tweak. Open your build.xml file and before </project> which is the last line in the file put the code below. So the code that you have to add must be between --> and </project> lines The code: <target name="package-for-store" depends="jar"> <!-- Change the value of this property to be the name of your JAR, minus the .jar extension. It should not have spaces. <property name="store.jar.name" value="MyJarName"/> --> <property name="store.jar.name" value="YourSoftwareName"/> <!-- don't edit below this line --> <property name="store.dir" value="store"/> <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/> <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/> <delete dir="${store.dir}"/> <mkdir dir="${store.dir}"/> <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip"> <zipgroupfileset dir="dist" includes="*.jar"/> <zipgroupfileset dir="dist/lib" includes="*.jar"/> <manifest> <attribute name="Main-Class" value="${main.class}"/> </manifest> </jar> <zip destfile="${store.jar}"> <zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/> </zip> <delete file="${store.dir}/temp_final.jar"/> </target> You have to replace YourSoftwareName with your software name.
0 Comments
To set a cursor if java you need to do this setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); WAIT_CURSOR is just an example you can set what you want.
To add an icon to your Java software that appear in the upper left and in the bottom bar add this code at the constructor of your main class Note: this is not the icon that the executable jar file will have setIconImage(Toolkit.getDefaultToolkit().getImage( getClass().getResource("/path/to/the/icon")));
Use this code to copy text to your clipboard: StringSelection stringSelection = new StringSelection (sb.toString()); Clipboard clpbrd = Toolkit.getDefaultToolkit ().getSystemClipboard (); clpbrd.setContents(stringSelection, null); Click Ctrl+I (in Netbeans) to import any missing classes if you need any If you populate dropdown box in run time to get the item text that the user selected use this code: string item = e.ClickedItem.Text
To add a column to an already exists table use this code to do it string[] sql_array = new string[] { "ALTER TABLE table_name ADD COLUMN column_name column_cons." }; foreach (string sql_com in sql_array) { m_dbConnection = new SQLiteConnection(sql_path); m_dbConnection.Open(); try { string sql = sql_com; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); } catch (Exception ex) { //catch exception } finally { m_dbConnection.Close(); m_dbConnection.Dispose(); GC.Collect(); } } This command "ALTER TABLE table_name ADD COLUMN column_name column_cons."
example: ALTER TABLE employees ADD COLUMN age INT the command that tell SQLite database to create a column in the database. You can add as much as you want in the array to create the desire number of columns If you want to make a software that deal with files or folders and you want to open windows explorer and select the file and folder use this code string path = path_to_your_file_or_folder; Process.Start("explorer.exe", @"/select, " + "\"" + path + "\""); select your path and call Process.Start method and windows explorer will open while the file or folder is being selected;
If you want to add a button in a textbox put this code in Load method or in a method and call it when windows load (Load method) private void Form1_Load(object sender, EventArgs e) { var btn = new Button(); btn.Size = new Size(25, yourtextbox.ClientSize.Height + 2); btn.Location = new Point(yourtextbox.ClientSize.Width - btn.Width, -1); btn.Cursor = Cursors.Default; btn.Image = Properties.Resources.Icon_name_in_resource; toolTip1.SetToolTip(btn, "Sometext"); btn.Click += btn_Click; yourtextbox.Controls.Add(btn); //Send EM_SETMARGINS to prevent text from disappearing underneath the button SendMessage(yourtextbox.Handle, 0xd3, (IntPtr)2, (IntPtr)(btn.Width << 16)); base.OnLoad(e); } [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); private void btn_Click(object sender, EventArgs e) { MessageBox.Show("hello world"); } Just change the code in black and it will work like charm.
To call in a method in another form (not in another class) you can use this code which will easily let you call the method if (System.Windows.Forms.Application.OpenForms["Form1"] != null) { (System.Windows.Forms.Application.OpenForms["Form1"] as Form1).Method() } You can change 'Form1' to the name of the form you need.
To control your GUI better, it is better to have a knowledge how your labels are in the design time without having to select the label every time you need to know. You can do this by using a simple code that create a normal label but with border in the design time by using the below source code. Make a .cs file put it in your package and build your package them in toolbox project's components you will find MyLabel item using System;
using System.Drawing; using System.Windows.Forms; namespace Owf { public class MyLabel : Label { public MyLabel() { InitializeComponent(); } private void InitializeComponent() { this.SuspendLayout(); // // MyLabel // this.Paint += new System.Windows.Forms.PaintEventHandler(this.MyLabel_Paint); this.ResumeLayout(false); } private void MyLabel_Paint(object sender, PaintEventArgs e) { if (this.DesignMode) { using (Pen pen = new Pen(Color.Gray)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; e.Graphics.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1); } } } } } |
SamiHi, I program in C# and also in Java. I hope that i will be useful for you with these basic tips and tricks in programming ArchivesCategories |