Results 1 to 6 of 6
  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Version information

    Hi,

    I have an Java application. I would like to make a "About" window with some information, and inside this information on the version and build date of my application.
    Any suggestion/tutorials on how to do this?
    Last edited by Norm; 09-04-2012 at 04:51 PM. Reason: Moved to New section

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Version information

    How do other programs do it? A very common way is a menu item that displays a dialog window.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Version information

    Yes, thats exactly what I want to do, but the information inside this dialog: I would like this to be information to be updated automatically when I build my project.
    i.e.: Version 1.01 date is today. When I build my project tomorrow, it is updated with tomorrows date and version 1.02. Is this possible?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Version information

    I would like this to be information to be updated automatically when I build my project.
    That sounds like a pre-process program that would update the source before javac compiles it. I don't think it is part of Oracle's java packages or utilities.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,805
    Rep Power
    19

    Default Re: Version information

    You'd need to dig through your build engine (eg Ant, Maven etc etc).
    They can all do this sort of thing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Version information

    I really should learn to use one of those preprocessors. If I need a version number, I usually just make it a public static final constant in my main class.

    But as for the rest... here's the about dialog from one of my apps. It has an image, a copyright notice, and some information gleaned from the system properties in a scrollable window. Clicking the copy button copies that information to the system clipboard so users can paste it into bug reports. I laid out the components in NetBeans and then modified the generated code by hand.

    Java Code:
    package krum.weaponm.gui;
    
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.datatransfer.StringSelection;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import javax.swing.GroupLayout;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.LayoutStyle;
    import javax.swing.WindowConstants;
    import javax.swing.border.BevelBorder;
    import javax.swing.text.DefaultCaret;
    
    import krum.weaponm.WeaponM;
    
    public class AboutDialog extends JDialog {
    	private static final long serialVersionUID = 1L;
    
    	protected Frame parent;
    	protected JButton closeButton;
    	protected JButton copyButton;
    	protected JLabel imageLabel;
    	protected JPanel copyrightPanel;
    	protected JScrollPane scrollPane;
    	protected JTextArea infoTextArea;
    
    	public static void showDialog(Frame parent) {
    		new AboutDialog(parent).setVisible(true);
    		// thread resumes when dialog is hidden
    	}
    	
    	protected AboutDialog(Frame parent) {
    		super(parent, true);
    		this.parent = parent;
    		initComponents();
    		setLocationRelativeTo(parent);
    	}
    
    	protected void initComponents() {
    		imageLabel = new JLabel();
    		copyrightPanel = new JPanel();
    		infoTextArea = new JTextArea();
    		scrollPane = new JScrollPane(infoTextArea);
    		closeButton = new JButton();
    		copyButton = new JButton();
    
    		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    		setTitle("About Weapon M");
    		setResizable(false);
    
    		imageLabel.setIcon(new ImageIcon(parent.getIconImage()));
    		imageLabel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    		imageLabel.setToolTipText("Forged in the fires of Betelgeuse!");
    
    		copyrightPanel.setLayout(new BoxLayout(copyrightPanel, BoxLayout.Y_AXIS));
    		JLabel copyrightLabel1 = new JLabel("Copyright 2012, Kevin Krumwiede");
    		copyrightLabel1.setAlignmentX(CENTER_ALIGNMENT);
    		copyrightPanel.add(copyrightLabel1);
    		JLabel copyrightLabel2 = new JLabel("All Rights Reserved");
    		copyrightLabel2.setAlignmentX(CENTER_ALIGNMENT);
    		copyrightPanel.add(copyrightLabel2);
    		
    		scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    		// this is kind of hackish, but it keeps the scroll pane from widening itself
    		scrollPane.setMaximumSize(new Dimension(imageLabel.getPreferredSize().width, Integer.MAX_VALUE));
    		
    		// this keeps the scroll pane scrolled to the top
    		DefaultCaret caret = (DefaultCaret) infoTextArea.getCaret();
    		caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    		
    		infoTextArea.append("Weapon M version: " + WeaponM.VERSION + "\n");
    		infoTextArea.append("Java vendor: " + System.getProperty("java.vendor") + "\n");
    		infoTextArea.append("Java version: " + System.getProperty("java.version") + "\n");
    		infoTextArea.append("Runtime name: " + System.getProperty("java.runtime.name") + "\n");
    		infoTextArea.append("Runtime version: " + System.getProperty("java.runtime.version") + "\n");
    		infoTextArea.append("VM name: " + System.getProperty("java.vm.name") + "\n");
    		infoTextArea.append("VM version: " + System.getProperty("java.vm.version") + "\n");
    		infoTextArea.append("OS name: " + System.getProperty("os.name") + "\n");
    		infoTextArea.append("OS version: " + System.getProperty("os.version") + "\n");
    		infoTextArea.append("OS architecture: " + System.getProperty("os.arch")); // no newline
    		infoTextArea.setEditable(false);
    		
    		closeButton.setText("Close");
    		closeButton.setMnemonic('o');
    		closeButton.addActionListener(new ActionListener() {
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				dispose();
    			}
    		});
    		
    		copyButton.setText("Copy");
    		copyButton.setMnemonic('C');
    		copyButton.addActionListener(new ActionListener() {
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				StringSelection text = new StringSelection(infoTextArea.getText());
    				getToolkit().getSystemClipboard().setContents(text, text);
    			}
    		});
    
    		// layout shizzle
    		GroupLayout layout = new GroupLayout(getContentPane());
    		getContentPane().setLayout(layout);
    		layout.setHorizontalGroup(layout
    				.createParallelGroup(GroupLayout.Alignment.LEADING)
    				.addGroup(
    						layout.createSequentialGroup()
    								.addContainerGap()
    								.addGroup(
    										layout.createParallelGroup(
    												GroupLayout.Alignment.LEADING)
    												.addGroup(
    														GroupLayout.Alignment.TRAILING,
    														layout.createSequentialGroup()
    																.addComponent(
    																		copyButton)
    																.addPreferredGap(
    																		LayoutStyle.ComponentPlacement.RELATED)
    																.addComponent(
    																		closeButton))
    												.addGroup(
    														layout.createParallelGroup(
    																GroupLayout.Alignment.TRAILING,
    																false)
    																.addComponent(
    																		scrollPane,
    																		GroupLayout.Alignment.LEADING)
    																.addComponent(
    																		copyrightPanel,
    																		GroupLayout.Alignment.LEADING,
    																		GroupLayout.DEFAULT_SIZE,
    																		GroupLayout.DEFAULT_SIZE,
    																		Short.MAX_VALUE)
    																.addComponent(
    																		imageLabel,
    																		GroupLayout.Alignment.LEADING,
    																		GroupLayout.DEFAULT_SIZE,
    																		GroupLayout.DEFAULT_SIZE,
    																		Short.MAX_VALUE)))
    								.addContainerGap()));
    		layout.setVerticalGroup(layout.createParallelGroup(
    				GroupLayout.Alignment.LEADING)
    				.addGroup(
    						layout.createSequentialGroup()
    								.addContainerGap()
    								.addComponent(imageLabel)
    								.addPreferredGap(
    										LayoutStyle.ComponentPlacement.RELATED)
    								.addComponent(copyrightPanel,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addPreferredGap(
    										LayoutStyle.ComponentPlacement.RELATED)
    								.addComponent(scrollPane,
    										GroupLayout.PREFERRED_SIZE, 53,
    										GroupLayout.PREFERRED_SIZE)
    								.addPreferredGap(
    										LayoutStyle.ComponentPlacement.RELATED)
    								.addGroup(
    										layout.createParallelGroup(
    												GroupLayout.Alignment.BASELINE)
    												.addComponent(closeButton)
    												.addComponent(copyButton))
    								.addContainerGap(GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE)));
    
    		getRootPane().setDefaultButton(closeButton);
    		pack();
    	}
    }
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Replies: 0
    Last Post: 05-09-2011, 09:37 AM
  2. Replies: 5
    Last Post: 04-27-2011, 09:14 PM
  3. java -version pointing to older version
    By deepakts in forum New To Java
    Replies: 4
    Last Post: 05-06-2010, 09:59 AM
  4. Replies: 0
    Last Post: 09-14-2008, 03:47 PM
  5. using different JDK version in one IDE
    By happyknappy in forum New To Java
    Replies: 3
    Last Post: 09-02-2008, 02:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •