微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将metatag添加到此messagebubble

如何解决将metatag添加到此messagebubble

在这里JavaFX WhatApp-Like ConversationView)找到了这个messagebubble设计,我正在尝试向它们添加一些元标记。我的意思是,我在消息提示框的右下角有时间和日期。

我目前仅以某种方式修改了气泡,使它们实际上符合我的“需求”。我现在的实际问题是我不知道如何在此气泡的右下角获得另一个标签

public class MessageBubble extends HBox
{

@Getter
@Setter
private UUID senderId;
@Getter
@Setter
private UUID messageId;

private final Color DEFAULT_SENDER_COLOR = GUI.getInstance().getCustomGreen();
private final Color DEFAULT_RECEIVER_COLOR = Color.WHITE;
private final Paint Meta_COLOR = Color.rgb(140,140,140);

private Background DEFAULT_SENDER_BACKGROUND,DEFAULT_RECEIVER_BACKGROUND;

private final String message;

private final SpeechDirection direction;

private Label displayedText,MetaText,dateText,usernameText;

public MessageBubble(String message,SpeechDirection direction)
{
    this.message = message;
    this.direction = direction;
    initialiseDefaults();
    setupElements();
}


private void initialiseDefaults()
{
    DEFAULT_SENDER_BACKGROUND = new Background(
            new BackgroundFill(DEFAULT_SENDER_COLOR,new CornerRadii(5,5,false),Insets.EMPTY));
    DEFAULT_RECEIVER_BACKGROUND = new Background(
            new BackgroundFill(DEFAULT_RECEIVER_COLOR,Insets.EMPTY));
}

private void setupElements()
{
    displayedText = new Label(message);
    displayedText.setPadding(new Insets(10));
    displayedText.setTextFill(Color.BLACK);
    displayedText.setWrapText(true);

    if (direction == SpeechDirection.LEFT)
    {
        configureForReceiver();
    } else
    {
        configureForSender();
    }
}

private void configureForSender()
{
    displayedText.setBackground(DEFAULT_SENDER_BACKGROUND);
    displayedText.setAlignment(Pos.CENTER_RIGHT);

    HBox container = new HBox(displayedText,MetaText);
    container.setPadding(new Insets(10,15,0));
    //Use at most 60% of the width provided to the SpeechBox for displaying the message
    container.maxWidthproperty().bind(widthproperty().multiply(0.6));

    getChildren().setAll(container);
    setAlignment(Pos.CENTER_RIGHT);
}

private void configureForReceiver()
{
    displayedText.setBackground(DEFAULT_RECEIVER_BACKGROUND);
    displayedText.setAlignment(Pos.CENTER_LEFT);

    HBox container = new HBox(displayedText);
    container.setPadding(new Insets(10,10,15));
    //Use at most 60% of the width provided to the SpeechBox for displaying the message
    container.maxWidthproperty().bind(widthproperty().multiply(0.6));
    getChildren().setAll(container);
    setAlignment(Pos.CENTER_LEFT);
}
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。