JListBackground.java Source code

Java tutorial

Introduction

Here is the source code for JListBackground.java

Source

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class JListBackground extends JPanel {
    private static final Color lightBlue = new Color(153, 204, 255);

    public JListBackground() {
        super();
        setBackground(lightBlue);
    }

    public static void addComponentsToPane(Container pane) {
        String[] bruteForceCode = { "int count = 0", "int m = mPattern.length();", "int n = mSource .length();",
                "outer:", " ++count;", " }", " return count;", "}" };
        JList list = new JList(bruteForceCode);
        Border etch = BorderFactory.createEtchedBorder();
        list.setBorder(BorderFactory.createTitledBorder(etch, "Brute Force Code"));
        JPanel listPanel = new JPanel();
        listPanel.add(list);
        listPanel.setBackground(lightBlue);
        list.setBackground(lightBlue);

        pane.add(listPanel, BorderLayout.CENTER);
        pane.setBackground(lightBlue);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Brute Force Algorithm");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addComponentsToPane(frame.getContentPane());
        frame.pack();
        frame.setSize(800, 600);
        frame.setVisible(true);
    }
}