Creating a table interface in java

How to create an interface similar to the following in Java (tweetie)?

alt text

I was thinking about using JTable with a single column and a custom cell that has an image in it ... not sure how to do this.

+3
source share
2 answers

The simplest way (I would do it) would be to use Vertical BoxLayouton JPanel. Each tweet will then be its own JPanel( TweetPanel extends JPanel) s BorderLayout, where the image is in WEST and the tweet text is in the CENTER.

Below is a description of how I was going to lay out one of the panels of the restaurant.

public ResturantPanel extends JPanel {

    public ResturantPanel(String name, String address, List<String> reviews, Icon icon){
        setLayout(new BorderLayout());
        JLabel iconLabel = new JLabel(theIcon);
        JLabel nameLabel = new JLabel(name);
        JLabel addressLabel = new JLabel(address);
        JPanel southReviewPanel = new JPanel();
        southReviewPanel.setLayout(new BoxLayout(southReviewPanel, BoxLayout.Y_AXIS);
        for (String review: reviews) {
            southReviewPanel.add(new JTextArea(review));
        }
        add(southReviewPanel);
        add(iconLabel, BorderLayout.West);
        JPanel northPane = new JPanel();
        northPane.setLayout(new BoxLayout(northPane, BoxLayout.Y_AXIS));
        northPane.add(nameLabel);
        northPane.add(addressLabel);
        add(northPane, BorderLayout.North);
    }
}

, . . , , , southReviewPanel, southReviewPanel, , , .

JPanel JScrollPane, .

+2

, JList, . , , . (getListCellRendererComponent), Component, .

+3

Source: https://habr.com/ru/post/1775007/


All Articles