Logo F2FInterview

Swing Interview Questions

Q   |   QA

This is another category of Swing interview questions asked in IB whether they will give you code and asked what would be the output , how will the GUI look like. This type of question is based upon how well you understand and visualize the code. Whether you are familiar with default layout manager of various component classes or not e.g. default layout of JFrame is BorderLayout.

This is an excellent java swing interview questions which is based on real world task and focus on JList component, Sorting and customizing JList model. For sorting you can use comparable in Java and by customizing the JList model you can display content as requested. Once you successfully answer this question there may be some followup on customizing the color of cell etc which can be done by customizing renderer.

The feature that is used in swing consists of accessibility technology that allows the class archives like JAR file. This file resides on separate machine and can not be accessed without the permissions given from the owner. Java is used to load the technology in the virtual machine that is used as an application. The technologies allow the replacement to be done using the virtual machine. It uses the queue method and the class as java.awt.EventQueue. The properties are used using the configuration file that is stored in awt.properties and it consists of all the specialized classes. Virtual machine in Java accesses the configuration file accessibility.properties that is contained in the jre/lib directory to allow the namespaces to be fetched to execute the process. The format is given of awt.properties file as:

# Assistive technologies
# Key names

JEditorPane class is used to display the HTML content that is being written using the classes. When there is a file consisting of the HTML text gives the request to read the file identify the method to read the HTML text using the read() method that is given in HTMLEditorKit. This kit provides lot of tools that delegates the file to a separate parser object. This kid also consists of tools and the abstract inner class consisting of the method as:

public abstract void parse(Reader r, ParserCallback cb) throws IOException

The read() method calls the getParser() method allowing the subclasses to parse the object and use the HTML text. The parser currently uses the package javax.swing.text.html.parser that allow the reading of the file and parse the HTML code. The parameter of the type ParserCallback is used to communicate the progress of the process that is parsing the HTML file.

In the parse() method we listed earlier, you'll notice a very important parameter of type
ParserCallback . This is how the parser communicates its progress. 

To paint the off-screen buffer in swings requires the paint component that is using an image allowing easy to create set of images and its components in different states. This image that is stored, remain useful for automated regression testing that is also known as the golden image approach that is used to compare the images with the current and old images that uses the last stable build of the image. The code that displays it is as follows:

JButton b = new JButton("Image buffer");
button.setSize(100, 50);
// This set the initial size of the image.
BufferedImage image = new BufferedImage(b.getWidth(), b.getHeight(),
Graphics g = image.getGraphics();
ImageIO.write(image, "png", new File("image.png")); 

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: