Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

  • Helloworld922's Java Tips

    by Published on August 4th, 2010 04:10 PM
    1. Categories:
    2. Helloworld922's Java Tips

    Introduction

    File filters are an easy check to see if a file meets some specific criteria. Generally, these are used to limit the available list of files to open when the user is shown a file chooser dialog (JFileChooser). While there is no limit to see if a file is to be displayed (it could even be random), the most common kind of filter is to filter by the file extension. In this tip, I'll go through the basics of creating your own file filters and how to use them with your JFileChooser.

    Difficulty: Easy-Medium. I'm assuming you have some experience with the Java language syntax, but extensive knowledge is not necessary. I will only discuss portions of JFileChooser that pertain to the file filters feature.

    Creating the File Filter

    To create your own file filter, all you need to do is extend the FileFilter class and implement the two abstract methods accept() and getDescription().

    public class TextFileFilter extends FileFilter
    {
         public boolean accept(File f)
        {
            if(f.isDirectory())
            {
                return true;
            }
            return f.getName().endsWith(".txt");
        }
     
        public String getDescription()
        {
            return "Text files (*.txt)";
        }
    }
    ...
    by Published on July 29th, 2010 04:13 PM
    1. Categories:
    2. Helloworld922's Java Tips

    Introduction

    This tutorial is focused on covering the basics of create an interactive console for Jython that you can embed into your Swing applications.

    Items that will be covered in this topic:

    1. "Piping" input/output streams using Java.
    2. Using document filters to change where text is inputted, or even prevent text from being added.
    3. Implementing a "command history" which can remember a commands that have been implemented.
    4. Using Jython from your Java program.

    Required tools

    1. All the basic tools you use for creating regular Java Swing applications.
    2. Jython. This implementation uses Jython 2.5.1, the current release at this writing. You can find the latest version here

    Difficulty: Medium-Hard. I'm assuming the reader has a thorough knowledge of the Java language and some experience with using Swing, as well as some knowledge of multi-threading in Java (very basic knowledge). There will also be exposure to some "lesser known" portions of the Java API, but I'll try to explain those when they come up. I will also explain a little bit of how to use external libraries from the Eclipse IDE.
    ...
    by Published on July 5th, 2010 04:08 PM
    1. Categories:
    2. Helloworld922's Java Tips

    Introduction

    In this Java tip, I will go through a few basic tools provided by the Eclipse IDE for navigating through your code.

    Tools that will be covered:

    1. Using the Outline tool
    2. View History tools
    3. Showing code of selected Item
    4. Code Folding
    5. Open Declaration

    For this tip, you will want to get the Eclipse Helios IDE* (also known as Eclipse 3.6, it was released June 24, 2010).

    Download link: Eclipse Downloads.

    *note: older Eclipse IDE's are likely to have some or all of these features, but I can't guarantee that all of them will be there, or if they will even have the same functionality.

    Eclipse Code Outline tool

    The outline tool is a nice little tool that shows an overview of the current file opened.
    ...