Displaying Scrolling List of Database Items

Question:
I want to display a scrolling list of items from a database:

 product | description | manu | expiration | product | description | manu | expiration | product | description | manu | expiration | product | description | manu | expiration | product | description | manu | expiration | product | description | manu | expiration | product | description | manu | expiration | 
What’s the best way to do it? And HOW do you do it?

Answer:
The easiest way of doing this is to use a monospaced font (so the columns line up) and fill the items into a single box.

Here is a sample Java applet that does just that.

Is that what you have in mind? It is also possible to have four listboxes and to keep them in synch. Submit another query if you need to see the code for that.

 import java.awt.*; import java.applet.*;  public class ColList extends Applet {  public void init()    {  setLayout(new GridLayout(1, 1));       items = new List(4, false);       items.addItem(new Item("KA-1094", "Pencil Sharpener", "Ultrasonic", "Aug 99").toString());       items.addItem(new Item("KB-1195", "Automatic Transmission", "Chevrolet", "Aug 97").toString());       items.addItem(new Item("KN-1339", "Can Opener", "Ultrasonic", "Feb 99").toString());       items.addItem(new Item("KP-1094", "Toaster Oven", "Royal Highness", "Mar 02").toString());       items.addItem(new Item("KU-2236", "Mending Kit", "Yue Loong", "Mar 98").toString());       items.addItem(new Item("KV-9401", "Chip Extraction Tool", "Intel", "Jan 99").toString());       items.addItem(new Item("KX-5734", "Laser Printer", "Lasertronic", "Aug 96").toString());       items.addItem(new Item("KZ-4453", "Dish Brush", "Yue Loong", "Jan 02").toString());              items.setFont(new Font("Courier", 8, Font.PLAIN));              add(items);    }        List items;     }   class Item {  public Item(String prod, String descr, String manu, String expire)    {  product = prod;       description = descr;       manufacturer = manu;       expiration = expire;    }    private static String pad(String s, int n)    {  if (n < s.length()) return s.substring(0, n);        StringBuffer sb = new StringBuffer(s);       sb.ensureCapacity(n);       for (int i = 0; i < n - s.length(); i++) sb.append(' ');       return sb.toString();    }    public String toString()    {  return pad(product, 8) + "|" + pad(description, 20) + "|" +          pad(manufacturer, 15) + "|" + expiration;    }    private String product;    private String description;    private String manufacturer;    private String expiration; }    

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job