2

here's my code:

public LMSPanel() {
    setLayout(new GridLayout(3,3,10,10));
    grid = new JLabel [10];
    int k = 1;
    while (k <= 9) {
        grid[k] = new JLabel("", JLabel.LEFT);
        grid[k].setText("");
        grid[k].setForeground(Color.BLACK);
        grid[k].setBackground(Color.GRAY);
        grid[k].setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
        add(grid[k]);
        k++;
    }
}

public void setHolding(Holding holding, int count2) {
    holdingCode = holding.getCode();
    if (holdingCode < 2000000) {
        lastBookCode = holdingCode;
        grid[count2].setForeground(Color.BLACK);
        grid[count2].setBackground(Color.GRAY);
        grid[count2].setBorder(BorderFactory.createLineBorder(Color.BLUE,10));
        grid[count2].setLayout(new GridLayout(4,1,5,5));
            JLabel text1 = new JLabel();
            JLabel text2 = new JLabel();
            JLabel text3 = new JLabel();
            JLabel text4 = new JLabel();
            text1.setText(" Holding Code: " + holding.getCode());
            text2.setText(" Book Title: " + holding.getTitle());
            text3.setText(" Standard Loan Fee: " + holding.getDefaultLoanFee());
            text4.setText(" Loan Period" + holding.getMaxLoanPeriod());
            grid[count2].add(text1);
            grid[count2].add(text2);
            grid[count2].add(text3);
            grid[count2].add(text4);
    } else if ...
    } 
}

I need to stop this code from replicating the inner grid contents, and I need to add a horizontal scroll action for oversized contents, but can't figure out how to do it.

Here's a screenshot: http://phuket.qsischool.org/downloads/DavesTempFolder/downloads.jpg

Any ideas? David.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
David
  • 21
  • 1
  • Seems more like you need a `JList` with horizontal scrolling enabled, or [`WrapLayout`](http://tips4java.wordpress.com/2008/11/06/wrap-layout/) in some form. BTW - For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Feb 22 '12 at 09:11
  • I'm not permitted to use either of the options you suggest. – David Feb 23 '12 at 03:26
  • *"I'm not permitted"* Why not? Is this [tag:homework]? BTW - I take it that statement did not rule out you posting an SSCCE, just the two suggestions in the first sentence. Is the SSCCE about ready to post? – Andrew Thompson Feb 23 '12 at 04:02

0 Answers0