Guys, Im wondering, If I have another class with a jpanel in it... and I add this to the jPanel, this should work correct?

jpanel.add(new DoughOverviewList());
jpanel.repaint();

for some reason its not showing in my jpanel,

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package doughtracker;

import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;

/**
 *
 * @author Acer
 */
public class DoughOverviewList extends JList {

    JScrollPane doughListScrollPane;
    DefaultListModel doughListModel;

    Border GrayLine = BorderFactory.createLineBorder(Color.LIGHT_GRAY);

    public DoughOverviewList() {

        super.setFont(new Font("Arial", Font.PLAIN, 16));
        super.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        super.setBorder(GrayLine);
        doughListScrollPane = new JScrollPane(this);
        doughListScrollPane.setBounds(DoughTracker.dimensions.doughCreatorWidth / 2, 120, 250, 345);
        doughListScrollPane.setBorder(GrayLine);
        doughListModel = new DefaultListModel();
        doughListModel.addElement("Testing ");

        super.setModel(doughListModel);
        super.setVisible(true);
        super.addListSelectionListener((ListSelectionEvent ev) -> {

        });

    }

}

Ive solved this problem, I relized i was adding the list but i was suposed to be adding the scrollPane,

So now i have this, but the list wont show, It shows for a split second, and than only the border shows?

Any thoughts?

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package doughtracker;

import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;

/**
 *
 * @author Acer
 */
public class DoughOverviewList extends JScrollPane {

    JList doughList;
    DefaultListModel doughListModel;

    Border GrayLine = BorderFactory.createLineBorder(Color.LIGHT_GRAY);

    public DoughOverviewList() {

        doughList = new JList();
        doughList.setFont(new Font("Arial", Font.PLAIN, 16));
        doughList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        doughList.setBorder(GrayLine);

        super.setBounds(DoughTracker.dimensions.doughCreatorWidth / 2+50, 120, 350, 500);
        super.setBorder(GrayLine);

        doughListModel = new DefaultListModel();
        doughListModel.addElement("Testing");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");      
        doughList.setModel(doughListModel);
        doughList.addListSelectionListener((ListSelectionEvent ev) -> {                
        });

          super.add(doughList);

    }
}

Thanks,

If solved, use the big gold button labeled "Answered? Mark as Solved".

Not sure why that code isn't working, but then I don't like the way you have forced the scroll pane into a class that should just be a list.
I simplified it like this and it works OK...

class DoughOverviewList extends JList {
    DefaultListModel doughListModel= new DefaultListModel();
    Border GrayLine = BorderFactory.createLineBorder(Color.LIGHT_GRAY);

    public DoughOverviewList() {
        setFont(new Font("Arial", Font.PLAIN, 16));
      setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        setBorder(GrayLine);
        //super.setBounds(150, 120, 350, 500);
        doughListModel.addElement("Testing");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");
        doughListModel.addElement("11");      
        setModel(doughListModel);
        addListSelectionListener(ev -> {                
            System.out.println(ev);
        });

    }

...

frame.add(new JScrollPane( new DoughOverviewList()));

Thank you sir, that was an easy fix, nice I with I would of thought of that,
Clean.

Thank you again as always sir,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.