【Vaadin flow 实战】第5讲-使用常用UI组件绘制页面元素
vaadin flow官方提供的UI组件文档地址是
https://vaadin.com/docs/latest/components
这里,我简单实战了官方提供的一些免费的UI组件,使用案例如下:
Accordion 手风琴
Accordion 手风琴效果组件
Accordion 手风琴-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s1 = new Span("手风琴");Accordion accordion = displayAccordion();add(s1,accordion);}private Accordion displayAccordion(){Accordion accordion = new Accordion();Span name = new Span("Sophia Williams");Span email = new Span("sophia.williams@company.com");Span phone = new Span("(501) 555-9128");VerticalLayout accordionItemLayout = new VerticalLayout(name,email, phone);accordionItemLayout.setSpacing(false);accordionItemLayout.setPadding(false);accordion.add("Personal information", accordionItemLayout);Span name2 = new Span("4027 Amber Lake Canyon");Span email2 = new Span("72333-5884 Cozy Nook");Span phone2 = new Span("Arkansas");VerticalLayout accordionItemLayout2 = new VerticalLayout(name2, email2, phone2);accordionItemLayout2.setSpacing(false);accordionItemLayout2.setPadding(false);accordion.add("Billing Address", accordionItemLayout2);return accordion;}
}
Avatar 头像
Avatar 头像
Avatar 头像-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s2 = new Span("Avatar 头像");Avatar avatarBasic = new Avatar();Avatar avatarName = new Avatar("TEST");AvatarGroup avatarGroup = new AvatarGroup();for (Country country : getCountries()) {String name = country.getName();AvatarGroup.AvatarGroupItem avatar = new AvatarGroup.AvatarGroupItem(name);avatarGroup.add(avatar);}Avatar userAvatar = new Avatar();userAvatar.setImage("https://images.unsplash.com/photo-1519681393784-d120267933ba?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80");add(s2,avatarBasic, avatarName,avatarGroup,userAvatar);}}
Badge 徽章
Badge 徽章-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s3 = new Span("Badge 徽章");Span pending = new Span("Pending");pending.getElement().getThemeList().add("badge");Span confirmed = new Span("Confirmed");confirmed.getElement().getThemeList().add("badge success");Span denied = new Span("Denied");denied.getElement().getThemeList().add("badge error");Span onHold = new Span("On hold");onHold.getElement().getThemeList().add("badge contrast");HorizontalLayout hLayout = new HorizontalLayout(pending, confirmed, denied, onHold);// Icon before textSpan pending1 = new Span(createIcon(VaadinIcon.CLOCK),new Span("Pending"));pending1.getElement().getThemeList().add("badge");
// Icon after textSpan pending2 = new Span(new Span("Pending"),createIcon(VaadinIcon.CLOCK));pending2.getElement().getThemeList().add("badge");HorizontalLayout h2Layout = new HorizontalLayout(pending1, pending2);add(s3,hLayout,h2Layout);}}
Button 按钮
Button 按钮-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s4 = new Span("Button");Button primaryButton = new Button("Primary");primaryButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);Button secondaryButton = new Button("Secondary");Button tertiaryButton = new Button("Tertiary");tertiaryButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);HorizontalLayout h3Layout = new HorizontalLayout(primaryButton, secondaryButton,tertiaryButton);Button primaryButton2 = new Button("Primary");primaryButton2.addThemeVariants(ButtonVariant.LUMO_PRIMARY, ButtonVariant.LUMO_ERROR);Button secondaryButton2 = new Button("Secondary");secondaryButton2.addThemeVariants(ButtonVariant.LUMO_ERROR);Button tertiaryButton2 = new Button("Tertiary");tertiaryButton2.addThemeVariants(ButtonVariant.LUMO_TERTIARY, ButtonVariant.LUMO_ERROR);HorizontalLayout h4Layout = new HorizontalLayout(primaryButton2, secondaryButton2,tertiaryButton2);Button primaryButton3 = new Button("Primary");primaryButton3.addThemeVariants(ButtonVariant.LUMO_PRIMARY,ButtonVariant.LUMO_WARNING);Button secondaryButton3 = new Button("Secondary");secondaryButton3.addThemeVariants(ButtonVariant.LUMO_WARNING);Button tertiaryButton3 = new Button("Tertiary");tertiaryButton3.addThemeVariants(ButtonVariant.LUMO_TERTIARY,ButtonVariant.LUMO_WARNING);HorizontalLayout h5Layout = new HorizontalLayout(primaryButton3, secondaryButton3,tertiaryButton3);Button largeButton = new Button("Large");largeButton.addThemeVariants(ButtonVariant.LUMO_LARGE);Button normalButton = new Button("Normal");Button smallButton = new Button("Small");smallButton.addThemeVariants(ButtonVariant.LUMO_SMALL);HorizontalLayout h6Layout = new HorizontalLayout(largeButton, normalButton,smallButton);add(s4,h3Layout,h4Layout,h5Layout,h6Layout);}}
CheckboxGroup 多选框
CheckboxGroup 多选框-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s5 = new Span("CheckboxGroup-demo");CheckboxGroup<String> checkboxGroup = new CheckboxGroup<>();checkboxGroup.setLabel("Export data");checkboxGroup.setItems("Order ID", "Product name", "Customer","Status");checkboxGroup.select("Order ID", "Customer");checkboxGroup.addThemeVariants(CheckboxGroupVariant.LUMO_VERTICAL);// 添加值改变事件监听器checkboxGroup.addValueChangeListener(event -> {// 处理选择的值Set<String> selectedValues = event.getValue();// 这里可以添加逻辑,比如更新 UI 或处理数据log.info("选中的checkbox:{}",selectedValues.toString());});add(s5,checkboxGroup);}}
ComboBox 组合框(下拉框)
ComboBox 组合框-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s6 = new Span("ComboBox");ComboBox<Country> countryComboBox = new ComboBox<>("Select Country");countryComboBox.setItems(getCountries()); // 设置 ComboBox 的项countryComboBox.setItemLabelGenerator(Country::getName); // 用于前端显示的标签// 监听选项变化countryComboBox.addValueChangeListener(event -> {Country selectedCountry = event.getValue();if (selectedCountry != null) {Long selectedId = selectedCountry.getId(); // 获取 ID// 在这里可以处理 ID,如存储到数据库等log.info("Selected country id: {}", selectedId);Notification.show("选中了"+selectedCountry.getName());}});add(s6,countryComboBox);}}
ConfirmDialog 对话框
ConfirmDialog 对话框-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s7 = new Span("ConfirmDialog");//demo1 删除确认Button deleteButton = new Button("删除项");// 添加按钮点击事件deleteButton.addClickListener(event -> {// 创建确认对话框ConfirmDialog dialog = new ConfirmDialog();dialog.setHeader("确认");dialog.setText("您确定要删除该项吗?");// 设置确认按钮的事件dialog.setCancelable(true);dialog.setConfirmText("确认");dialog.setConfirmButtonTheme("error primary");dialog.setCancelText("取消");dialog.addConfirmListener(confirmEvent -> {// 处理确认事件log.info("确认删除");Notification.show("项已删除!");});dialog.addCancelListener(cancelEvent -> {// 处理取消事件log.info("操作已取消");Notification.show("操作已取消!");});// 显示对话框dialog.open();});//demo2 使用建议Button recommendButton = new Button("提示");recommendButton.addClickListener(event -> {ConfirmDialog dialog = new ConfirmDialog();dialog.setHeader("导出失败");dialog.setText(new Html("<p>导出报告Q4时出错。请重试,如果问题仍然存在,请联系 <a href=\"mailto:support@company.com\">support@company.com</a></p>"));dialog.setConfirmText("我知道了");dialog.addConfirmListener(confirmEvent -> {// 处理确认事件log.info("我知道了");Notification.show("我知道了!");});// 显示对话框dialog.open();});//demo3 拒绝按钮Button rejectButton = new Button("拒绝保存");rejectButton.addClickListener(event -> {ConfirmDialog dialog = new ConfirmDialog();dialog.setHeader("未保存的更改");dialog.setText("您想在导航离开之前放弃或保存更改吗");dialog.setCancelable(true);dialog.setCancelText("取消");dialog.addCancelListener(cancelEvent -> {// 处理取消事件log.info("操作已取消");Notification.show("操作已取消!");});dialog.setRejectable(true);dialog.setRejectText("丢弃变更");dialog.setConfirmText("保存变更");// 显示对话框dialog.open();});add(s7,deleteButton,recommendButton,rejectButton);}}
DatePicker 日期选择
DatePicker 日期选择-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s8 = new Span("DatePicker");DatePicker datePicker = new DatePicker("选择日期");datePicker.setLabel("选择一个日期");// 设置日期格式datePicker.setI18n(new DatePicker.DatePickerI18n().setCancel("取消").setToday("今天").setMonthNames(List.of("一月", "二月", "三月", "四月", "五月", "六月","七月", "八月", "九月", "十月", "十一月", "十二月")));// 添加监听器以捕获日期选择事件datePicker.addValueChangeListener(event -> {// 获取选择的日期LocalDate date = event.getValue();log.info("选择的日期:{}",date.toString());});add(s8,datePicker);}}
DateTimePicker 日期时间选择
DateTimePicker 日期时间选择-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s9 = new Span("DateTimePicker");DateTimePicker dateTimePicker = new DateTimePicker("选择日期和时间");// 可以设置默认值dateTimePicker.setValue(LocalDateTime.now());// 你可以为选择事件添加监听器dateTimePicker.addValueChangeListener(event -> {LocalDateTime selectedDateTime = event.getValue();System.out.println("选择的日期时间: " + selectedDateTime);});add(s9,dateTimePicker);}}
TimePicker 时间选择
TimePicker 时间选择-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s010 = new Span("TimePicker");TimePicker timePicker = new TimePicker();timePicker.setLabel("Meeting time");timePicker.setStep(Duration.ofMinutes(30));timePicker.setValue(LocalTime.of(12, 30));add(s010,timePicker);}}
Dialog 弹窗
Dialog 弹窗-测试案例代码
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s10 = new Span("Dialog");Button showDialogButton = new Button("new弹窗");showDialogButton.addClickListener(event -> {Dialog dialog = new Dialog();dialog.setWidth("368px");dialog.setHeaderTitle("New employee");TextField tf1 = new TextField("First Name");tf1.setWidth("276px");TextField tf2 = new TextField("Last Name");tf2.setWidth("276px");VerticalLayout layout = new VerticalLayout();layout.add(tf1,tf2);dialog.add(layout);Button saveButton = new Button("Save",e->{String value = tf1.getValue();if (StringUtils.isEmpty(value)) {Notification.show("First Name 不能为空!");}else {s10.setText(value);// 关闭对话框dialog.close();}});saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);Button cancelButton = new Button("Cancel", e -> dialog.close());dialog.getFooter().add(cancelButton);dialog.getFooter().add(saveButton);// 显示对话框dialog.open();});Button openDialogButton = new Button("view弹窗", event -> openDialog());add(s10,showDialogButton,openDialogButton);}private void openDialog() {Dialog dialog = new Dialog();dialog.setWidth("388px"); // 设置弹窗宽度// 创建输入框TextField nameField = new TextField("Name", "Enter your name");nameField.setWidth("300px");nameField.setValue("test");nameField.setReadOnly(true);TextField emailField = new TextField("Email", "Enter your email");emailField.setWidth("300px");emailField.setValue("efdxuwef@163.com");emailField.setReadOnly(true);TextField addressField = new TextField("Address", "Enter your address");addressField.setWidth("300px");addressField.setValue("4188 Crystal Orchard, Mousie, USA");addressField.setReadOnly(true);VerticalLayout layout = new VerticalLayout();layout.add(nameField);layout.add(emailField);layout.add(addressField);// 添加输入框到对话框dialog.add(layout);dialog.setHeaderTitle("User details");Button closeButton = new Button(new Icon("lumo", "cross"),(e) -> dialog.close());closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);dialog.getHeader().add(closeButton);dialog.open();}
}
Input 各种输入窗
Input 各种输入窗-测试案例代码,需要在自定义css文件里配置css ,然后在Java中声明使用的组件css
.password-strength-week{color: red;
}.password-strength-moderate{color: yellowgreen;
}.password-strength-strong{color: darkgreen;
}
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s11 = new Span("各种输入窗");EmailField validEmailField = new EmailField();validEmailField.setLabel("Email address");validEmailField.getElement().setAttribute("name", "email");validEmailField.setValue("julia@email.com");validEmailField.setErrorMessage("Enter a valid email address");validEmailField.setPrefixComponent(VaadinIcon.ENVELOPE.create());validEmailField.setClearButtonVisible(true);NumberField dollarField = new NumberField();dollarField.setLabel("Balance");dollarField.setValue(200.0);Div dollarPrefix = new Div();dollarPrefix.setText("$");dollarField.setPrefixComponent(dollarPrefix);dollarField.setClearButtonVisible(true);IntegerField integerField = new IntegerField();integerField.setLabel("Quantity");integerField.setHelperText("Max 10 items");integerField.setRequiredIndicatorVisible(true);integerField.setMin(1);integerField.setMax(10);integerField.setValue(2);integerField.setStepButtonsVisible(true);integerField.setI18n(new IntegerField.IntegerFieldI18n().setRequiredErrorMessage("Field is required").setBadInputErrorMessage("Invalid number format").setMinErrorMessage("Quantity must be at least 1").setMaxErrorMessage("Maximum 10 items available"));BigDecimalField bigDecimalField = new BigDecimalField();bigDecimalField.setLabel("Result");bigDecimalField.setWidth("240px");bigDecimalField.setValue(new BigDecimal("948205817.472950487"));IntegerField xField = new IntegerField();xField.setLabel("X");xField.setValue(-1284);NumberField numberField = new NumberField();numberField.setLabel("Duration (hours)");numberField.setStep(0.5);numberField.setValue(12.5);numberField.setStepButtonsVisible(true);numberField.setI18n(new NumberField.NumberFieldI18n().setBadInputErrorMessage("Invalid number format").setStepErrorMessage("Duration must be a multiple of 0.5"));PasswordField passwordField1 = new PasswordField();passwordField1.setLabel("Password");passwordField1.setValue("Ex@mplePassw0rd");passwordField1.setClearButtonVisible(true);passwordField1.setPrefixComponent(VaadinIcon.LOCK.create());HorizontalLayout layout = new HorizontalLayout();
// layout.setPadding(true);layout.add(validEmailField);layout.add(dollarField);layout.add(integerField);layout.add(bigDecimalField);layout.add(xField);layout.add(numberField);layout.add(passwordField1);PasswordField passwordField = new PasswordField();passwordField.setLabel("Password2");Icon checkIcon = VaadinIcon.CHECK.create();checkIcon.setVisible(false);checkIcon.getStyle().set("color", "var(--lumo-success-color)");passwordField.setSuffixComponent(checkIcon);Div passwordStrength = new Div();Span passwordStrengthText = new Span("week");passwordStrengthText.setClassName("password-strength-week");passwordStrength.add(new Text("Password strength: "),passwordStrengthText);passwordField.setHelperComponent(passwordStrength);passwordField.setClearButtonVisible(false);passwordField.setValueChangeMode(ValueChangeMode.EAGER); //设置实时监听passwordField.addValueChangeListener(event -> {String value = event.getValue();log.info("ValueChangeListener value: {}" , value);if (value.length() <= 3) {checkIcon.setVisible(false);passwordStrengthText.setText("week");passwordStrengthText.setClassName("password-strength-week"); //使用了外部自定义CSS}if (value.length() >3 && value.length() <= 6) {checkIcon.setVisible(false);passwordStrengthText.setText("moderate");passwordStrengthText.setClassName("password-strength-moderate"); //使用了外部自定义CSS}if (value.length() >6 && value.length() <= 9) {passwordStrengthText.setText("strong");passwordStrengthText.setClassName("password-strength-strong"); //使用了外部自定义CSScheckIcon.setVisible(true);}});TextField textField = new TextField();textField.setLabel("Street Address");textField.setValue("Ruukinkatu 2");textField.setClearButtonVisible(true);textField.setPrefixComponent(VaadinIcon.MAP_MARKER.create());TextField phoneField = new TextField("Phone number");phoneField.setRequiredIndicatorVisible(true);phoneField.setPattern("^[+]?[\\(]?[0-9]{3}[\\)]?[\\-]?[0-9]{3}[\\-]?[0-9]{4,6}$");phoneField.setAllowedCharPattern("[0-9()+-]");phoneField.setMinLength(5);phoneField.setMaxLength(18);phoneField.setHelperText("Format: +(123)456-7890");phoneField.setI18n(new TextField.TextFieldI18n().setRequiredErrorMessage("Field is required").setMinLengthErrorMessage("Minimum length is 5 characters").setMaxLengthErrorMessage("Maximum length is 18 characters").setPatternErrorMessage("Invalid phone number format"));TextArea textArea = new TextArea();textArea.setLabel("Comment");textArea.setMaxLength(150);textArea.setValueChangeMode(ValueChangeMode.EAGER);textArea.addValueChangeListener(e -> {e.getSource().setHelperText(e.getValue().length() + "/" + 150);});textArea.setValue("Great job. This is excellent!");TextField findField = new TextField();findField.setPlaceholder("Search");findField.setPrefixComponent(new Icon("lumo", "search"));findField.setTooltipText("Wrap in “quotes” for exact phrase");add(s11,layout,passwordField,textField,phoneField,textArea,findField);}}
TabSheet 选项卡
TabSheet 选项卡-测试代码案例
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {TabSheet tabSheet = new TabSheet();tabSheet.add("Dashboard",new Div(new Text("This is the Dashboard tab content")));tabSheet.add("Payment",new Div(new Text("This is the Payment tab content")));tabSheet.add("Shipping",new Div(new Text("This is the Shipping tab content")));add(tabSheet);}
}
RadioButtonGroup 单选按钮组
RadioButtonGroup 单选按钮组-测试代码案例
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {RadioButtonGroup<String> radioGroup = new RadioButtonGroup<>();radioGroup.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);radioGroup.setLabel("Travel class");radioGroup.setItems("Economy", "Business", "First Class");radioGroup.addValueChangeListener(event -> {String value = event.getValue();log.info("RadioButtonGroup ValueChangeListener value: {}" , value);});add(radioGroup);
}
}
ProgressBar 进度条
ProgressBar 进度条-测试代码案例
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {
ProgressBar progressBar = new ProgressBar();progressBar.setValue(0.5);ProgressBar progressBar2 = new ProgressBar();progressBar2.setIndeterminate(true);// ContrastProgressBar progressBarContrast = new ProgressBar();progressBarContrast.addThemeVariants(ProgressBarVariant.LUMO_CONTRAST);progressBarContrast.setValue(0.5);// SuccessProgressBar progressBarSuccess = new ProgressBar();progressBarSuccess.addThemeVariants(ProgressBarVariant.LUMO_SUCCESS);progressBarSuccess.setValue(0.75);// ErrorProgressBar progressBarError = new ProgressBar();progressBarError.addThemeVariants(ProgressBarVariant.LUMO_ERROR);progressBarError.setValue(0.2);add(progressBar,progressBar2,progressBarContrast,progressBarSuccess,progressBarError);ProgressBar progressBarExport = new ProgressBar();progressBarExport.setIndeterminate(true);// Associates the labels with the bar programmatically, for screen
// readers:progressBarExport.getElement().setAttribute("aria-labelledby", "pblbl");progressBarExport.getElement().setAttribute("aria-describedby", "sublbl");NativeLabel progressBarLabel = new NativeLabel("Generating report...");progressBarLabel.setId("pblbl");progressBarLabel.addClassName(LumoUtility.TextColor.SECONDARY);Span progressBarSubLabel = new Span("Process can take upwards of 10 minutes");progressBarSubLabel.setId("sublbl");progressBarSubLabel.addClassNames(LumoUtility.TextColor.SECONDARY, LumoUtility.FontSize.XSMALL);add(progressBarLabel, progressBarExport, progressBarSubLabel);}}
MultiSelectComboBox 多选下拉框
MultiSelectComboBox 多选下拉框-测试代码案例
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {Span s16 = new Span("MultiSelectComboBox demo");MultiSelectComboBox<Country> comboBox = new MultiSelectComboBox<>("Countries");comboBox.setItems(getCountries());comboBox.setItemLabelGenerator(Country::getName);comboBox.addValueChangeListener(event -> {Set<Country> countrySet = event.getValue();log.info("countrySet: {}", countrySet);});add(s16,comboBox);
}
}
MessageInput 消息输入框
MessageInput 消息输入框-测试代码案例
@Slf4j
@PageTitle("HelpViewPage")
@Route(value = "helpView",layout = MainLayout.class)
@Menu(order = 5, icon = LineAwesomeIconUrl.FILE)
public class HelpView extends VerticalLayout{public HelpView() {
MessageInput input = new MessageInput();input.addSubmitListener(submitEvent -> {Notification.show("Message received: " + submitEvent.getValue(),3000, Notification.Position.MIDDLE);});add(input);}}
Notification 通知
Notification 通知–测试代码案例
Span s18 = new Span("Notification demo");Button toast1 = new Button("toast1", event -> {// When creating a notification using the `show` static method,
// the duration is 5-sec by default.Notification.show("Financial report generated");});Button toast2 = new Button("toast2", event -> {Notification notification = Notification.show("Application submitted!");notification.addThemeVariants(NotificationVariant.LUMO_SUCCESS);});Button toast3 = new Button("toast3",evt -> {Notification notification = new Notification();notification.addThemeVariants(NotificationVariant.LUMO_WARNING);Div text = new Div(new Text("Your session will expire in 5 minutes due to inactivity."),new HtmlComponent("br"),new Text("Close this warning to continue working."));Button closeButton = new Button(new Icon("lumo", "cross"));closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);closeButton.setAriaLabel("Close");closeButton.addClickListener(event -> {notification.close();});HorizontalLayout layoutH = new HorizontalLayout(text, closeButton);layoutH.setAlignItems(Alignment.CENTER);notification.add(layoutH);notification.open();});Button toast4 = new Button("toast4",evt -> {Notification notification = new Notification();notification.addThemeVariants(NotificationVariant.LUMO_ERROR);Div text = new Div(new Text("Failed to generate report"));Button closeButton = new Button(new Icon("lumo", "cross"));closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);closeButton.setAriaLabel("Close");closeButton.addClickListener(event -> {notification.close();});HorizontalLayout layoutH = new HorizontalLayout(text, closeButton);layoutH.setAlignItems(Alignment.CENTER);notification.add(layoutH);notification.open();});add(s18,toast1,toast2,toast3,toast4);
MultiSelectListBox 列表框
MultiSelectListBox 列表框-测试代码案例
//列表框允许用户从可滚动的项目列表中选择一个或多个值Span s19 = new Span("MultiSelectListBox demo");MultiSelectListBox<Country> listBox = new MultiSelectListBox<>();listBox.setItems(getCountries());listBox.select(getCountries().get(0), getCountries().get(3));listBox.setHeight("200px");listBox.setClassName("lstbox"); //这里使用了自定义CSS文件中的CSS类名listBox.setTooltipText("this is a listbox");// 设置展示给用户的名称listBox.setItemLabelGenerator(Country::getName);// 添加一个值改变监听器listBox.addValueChangeListener(event -> {String selectedCountries = event.getValue().stream().map(Country::getName).reduce((a, b) -> a + ", " + b).orElse("No countries selected");Notification.show(selectedCountries);});add(s19,listBox);
对应的自定义CSS配置
绘制自定义卡片
测试代码案例, 需要在自定义css文件里配置css ,然后在Java中声明使用的组件css
.card {transition: transform 0.2s;
}.card:hover {transform: scale(1.05);
}
Div card = new Div();card.setClassName("card"); //使用的自定义csscard.getElement().getStyle().set("border", "1px solid #ccc");card.getElement().getStyle().set("border-radius", "5px");card.getElement().getStyle().set("padding", "16px");card.getElement().getStyle().set("width", "300px");card.getElement().getStyle().set("box-shadow", "0 4px 8px rgba(0,0,0,0.1)");// 添加标题H3 title = new H3("Card Title");card.add(title);// 添加图片
// Image image = new Image("https://via.placeholder.com/300", "Placeholder image");Image image = new Image("https://images.unsplash.com/photo-1512273222628-4daea6e55abb?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80", "Placeholder image");image.setWidth("300px");card.add(image);// 添加按钮Button button = new Button("Click me");card.add(button);add(card);
FormLayout 表单布局
测试代码案例
Span fSpan = new Span("FormLayout demo");TextField firstName = new TextField("First name");TextField lastName = new TextField("Last name");TextField username = new TextField("Username");PasswordField password = new PasswordField("Password");PasswordField confirmPassword = new PasswordField("Confirm password");FormLayout formLayout = new FormLayout();formLayout.add(firstName, lastName, username, password, confirmPassword);formLayout.setResponsiveSteps(// Use one column by defaultnew FormLayout.ResponsiveStep("0", 1),// Use two columns, if layout's width exceeds 500pxnew FormLayout.ResponsiveStep("500px", 2));
// Stretch the username field over 2 columnsformLayout.setColspan(username, 2);add(fSpan,formLayout);
Upload 文件上传组件
测试代码案例
Span sSpan = new Span("Upload demo");MultiFileMemoryBuffer buffer = new MultiFileMemoryBuffer();Upload upload = new Upload(buffer);//限制上传文件格式// upload.setAcceptedFileTypes("application/pdf", ".pdf");//默认情况下,“上传”不限制可以上传的文件数量。但是,您可以设置文件计数限制upload.setMaxFiles(3);//设置最大字节数来限制文件大小。但默认情况下,没有限制// 10MBint maxFileSizeInBytes = 10 * 1024 * 1024;upload.setMaxFileSize(maxFileSizeInBytes);upload.addSucceededListener(event -> {String fileName = event.getFileName();log.info("fileName:{}", fileName);String mainName = FileNameUtil.mainName(fileName);log.info("file mainName:{}", mainName);String extName = FileNameUtil.extName(fileName);log.info("file extName:{}", extName);InputStream in = buffer.getInputStream(fileName);// Do something with the file data// processFile(inputStream, fileName);BufferedOutputStream out = FileUtil.getOutputStream("/Users/xxx/Documents/"+fileName);long copySize = IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE);System.err.println(copySize);IoUtil.closeIfPosible(in);IoUtil.closeIfPosible(out);});upload.addFileRejectedListener(event -> {String errorMessage = event.getErrorMessage();Notification notification = Notification.show(errorMessage, 5000,Notification.Position.MIDDLE);notification.addThemeVariants(NotificationVariant.LUMO_ERROR);});add(sSpan,upload);
Image 图片展示组件
测试代码案例
// Image imageTest = new Image("images/empty-plant.png", "My Alt Image");Image imageTest = new Image("https://images.unsplash.com/photo-1519681393784-d120267933ba?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80", "My Alt Image");SvgIcon svgIcon = new SvgIcon();svgIcon.setSrc("icons/hellokitty_1.svg");SvgIcon svgIcon2 = new SvgIcon();svgIcon2.setSrc("icons/hellokitty.svg");SvgIcon svgIcon3 = new SvgIcon();svgIcon3.setSrc("icons/hello.svg");add(imageTest,svgIcon,svgIcon2,svgIcon3);
相关文章:
【Vaadin flow 实战】第5讲-使用常用UI组件绘制页面元素
vaadin flow官方提供的UI组件文档地址是 https://vaadin.com/docs/latest/components这里,我简单实战了官方提供的一些免费的UI组件,使用案例如下: Accordion 手风琴 Accordion 手风琴效果组件 Accordion 手风琴-测试案例代码 Slf4j PageT…...
第三篇:模型压缩与量化技术——DeepSeek如何在边缘侧突破“小而强”的算力困局
——从算法到芯片的全栈式优化实践 随着AI应用向移动终端与物联网设备渗透,模型轻量化成为行业核心挑战。DeepSeek通过自研的“算法-编译-硬件”协同优化体系,在保持模型性能的前提下,实现参数量与能耗的指数级压缩。本文从技术原理、工程实…...
搜索与图论复习2最短路
单源最短路---所有边权是正数(Dijkstra算法O(n^2)--稠密图(邻接矩阵)和堆优化的Dijkstra算法O(mlogn)--稀疏图(邻接表)) 或存在负边权(Bellman-ford贝尔曼福特算法O(nm)和SPFA一般O(m) 最坏O(nm) ) 多源最短路---Floyd算法O(n^3) 一、迪杰斯特拉算法(Dijkstra):1…...
redis集群理论详解
一. Redis集群发展历程 本片文章只介绍集群理论知识,不包含Redis集群搭建教程 教程文章请点击docker搭建redis集群(三主三从) 阶段一:单机版Redis 优点: 简单:易于部署和使用,适合小型项目或初期…...
本地缓存~
前言 Caffeine是使用Java8对Guava缓存的重写版本,在Spring Boot 2.0中取而代之,基于LRU算法实现,支持多种缓存过期策略。 以下摘抄于https://github.com/ben-manes/caffeine/wiki/Benchmarks-zh-CN 基准测试通过使用Java microbenchmark ha…...
SpringBoot 整合 SpringMVC:SpringMVC的注解管理
分类: 中央转发器(DispatcherServlet)控制器视图解析器静态资源访问消息转化器格式化静态资源管理 中央转发器: 中央转发器被 SpringBoot 自动接管,不需要我们在 web.xml 中配置: <servlet><servlet-name>chapter2&l…...
YOLO11/ultralytics:环境搭建
前言 人工智能物体识别行业应该已经饱和了吧?或许现在并不是一个好的入行时候。 最近看到了各种各样相关的扩展应用,为了理解它,我不得不去尝试了解一下。 我选择了git里非常受欢迎的yolo系列,并尝试了最新版本YOLO11或者叫它ultr…...
扩散模型(三)
相关阅读: 扩散模型(一) 扩散模型(二) Latent Variable Space 潜在扩散模型(LDM;龙巴赫、布拉特曼等人,2022 年)在潜在空间而非像素空间中运行扩散过程,这…...
探索数学:从起源到未来的无尽旅程
数学的定义与本质 数学,这门古老而又充满魅力的学科,自人类文明诞生之初便如影随形。然而,要精准地定义数学并非易事,不同的学者从各自的视角出发,给出了多样的阐释。 亚里士多德将数学定义为 “数量科学”ÿ…...
OpenAI发布o3-mini:免费推理模型,DeepSeek引发的反思
引言 在人工智能领域,OpenAI再次引领潮流,推出了全新的推理模型系列——o3-mini。这一系列包括low、medium和high三个版本,旨在进一步推动低成本推理的发展。与此同时,OpenAI的CEO奥特曼也在Reddit的“有问必答”活动中罕见地公开…...
React中使用箭头函数定义事件处理程序
React中使用箭头函数定义事件处理程序 为什么使用箭头函数?1. 传递动态参数2. 避免闭包问题3. 确保每个方块的事件处理程序是独立的4. 代码可读性和维护性 示例代码总结 在React开发中,处理事件是一个常见的任务。特别是当我们需要传递动态参数时&#x…...
自制虚拟机(C/C++)(三、做成标准GUI Windows软件,扩展指令集,直接支持img软盘)
开源地址:VMwork 要使终端不弹出, #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") 还要实现jmp near 0x01类似的 本次的main.cpp #include <graphics.h> #include <conio.h> #include <windows.h> #includ…...
C# 语言基础全面解析
.NET学习资料 .NET学习资料 .NET学习资料 一、引言 C# 是一种功能强大、面向对象且类型安全的编程语言,由微软开发,广泛应用于各种类型的软件开发,从桌面应用、Web 应用到游戏开发等领域。本文将全面介绍 C# 语言的基础知识,帮…...
MySQL的覆盖索引
MySQL的覆盖索引 前言 当一个索引包含了查询所需的全部字段时,就可以提高查询效率,这样的索引又被称之为覆盖索引。 以MySQL常见的三种存储引擎为例:InnoDB、MyISAM、Memory,对于覆盖索引提高查询效率的方式均不同,…...
Hutool工具类
Hutool 是一个非常流行的 Java 工具类库,它提供了丰富的功能来简化开发中的常见任务,比如文件操作、加密、日期处理、字符串操作、数据库工具等。它是一个轻量级的工具库,可以减少开发者编写常用代码的工作量,提高开发效率。 主要…...
C++模板编程——可变参函数模板之折叠表达式
目录 1. 什么是折叠表达式 2. 一元左折 3. 一元右折 4. 二元左折 5. 二元右折 6. 后记 上一节主要讲解了可变参函数模板和参数包展开,这一节主要讲一下折叠表达式。 1. 什么是折叠表达式 折叠表达式是C17中引入的概念,引入折叠表达式的目的是为了…...
使用MATLAB进行雷达数据采集可视化
本文使用轮趣科技N10雷达,需要源码可在后台私信或者资源自取 1. 项目概述 本项目旨在通过 MATLAB 读取 N10 激光雷达 的数据,并进行 实时 3D 点云可视化。数据通过 串口 传输,并经过解析后转换为 三维坐标点,最终使用 pcplayer 进…...
【Linux系统】信号:信号保存 / 信号处理、内核态 / 用户态、操作系统运行原理(中断)
理解Linux系统内进程信号的整个流程可分为: 信号产生 信号保存 信号处理 上篇文章重点讲解了 信号的产生,本文会讲解信号的保存和信号处理相关的概念和操作: 两种信号默认处理 1、信号处理之忽略 ::signal(2, SIG_IGN); // ignore: 忽略#…...
在C语言多线程环境中使用互斥量
如果有十个银行账号通过不同的十条线程同时向同一个账号转账时,如果没有很好的机制保证十个账号依次存入,那么这些转账可能出问题。我们可以通过互斥量来解决。 C标准库提供了这个互斥量,只需要引入threads.头文件。 互斥量就像是一把锁&am…...
PHP代码审计学习02
目录 代码审计一般思路 Beescms代码审计(upload) Finecms基于前台MVC任意文件上传挖掘思路 CLTPHP基于thinkphp5框架的文件上传挖掘思路 今天来看PHP有框架MVC类,文件上传,断点调试挖掘。 同样还是有关键字搜索和功能点抓包两…...
基于微信小程序的医院预约挂号系统设计与实现(LW+源码+讲解)
专注于大学生项目实战开发,讲解,毕业答疑辅导,欢迎高校老师/同行前辈交流合作✌。 技术范围:SpringBoot、Vue、SSM、HLMT、小程序、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、安卓app、大数据、物联网、机器学习等设计与开发。 主要内容:…...
大厂面试题备份20250201
20250201 面试策略 如果三面往后遇到传说中让人忍受不了的业余面试官,就舔着苟过去,入职大概率见不着他,但一二面遇到,反问环节就主动说不够match,让释放流程。 机器/深度学习 百面机器学习 5.4 通用CS 计算机网…...
Spring Boot 实例解析:HelloWorld 探究
POM 文件剖析: 父项目: <parent><groupId>org.springframework.boot</groupId><artifactId>spring‐boot‐starter‐parent</artifactId><version>1.5.9.RELEASE</version> </parent> 他的父项目是 <…...
【课题推荐】基于t分布的非高斯滤波框架在水下自主导航中的应用研究
水下自主导航系统在海洋探测、环境监测及水下作业等领域具有广泛的应用。然而,复杂的水下环境常常导致传感器输出出现野值噪声,这些噪声会严重影响导航信息融合算法的精度,甚至导致系统发散。传统的卡尔曼滤波算法基于高斯噪声假设࿰…...
【C++语言】卡码网语言基础课系列----12. 位置互换
文章目录 练习题目位置互换具体代码实现 小白寄语诗词共勉 练习题目 位置互换 题目描述: 给定一个长度为偶数位的字符串,请编程实现字符串的奇偶位互换。 输入描述: 输入包含多组测试数据。 输入的第一行是一个整数n,表示有测试…...
洛谷的更多功能(不会像其他文章那样复杂且仅支持Edge浏览器)
第一步:下载《洛谷美化 (1).zip》文件夹。 会出现这样的文件夹: 注意:Edge.txt和洛谷前提1.txt是一样的哟! 第二步:篡改猴 先打开Edge.txt或者是洛谷前提1.txt文件,打开后复制粘贴到你的Edge浏览器并打开…...
C++编程语言:抽象机制:模板(Bjarne Stroustrup)
目录 23.1 引言和概观(Introduction and Overview) 23.2 一个简单的字符串模板(A Simple String Template) 23.2.1 模板的定义(Defining a Template) 23.2.2 模板实例化(Template Instantiation) 23.3 类型检查(Type Checking) 23.3.1 类型等价(Type Equivalence) …...
女生年薪12万,算不算属于高收入人群
在繁华喧嚣的都市中,我们时常会听到关于收入、高薪与生活质量等话题的讨论。尤其是对于年轻女性而言,薪资水平不仅关乎个人价值的体现,更直接影响到生活质量与未来的规划。那么,女生年薪12万,是否可以被划入高收入人群…...
2181、合并零之间的节点
2181、[中等] 合并零之间的节点 1、问题描述: 给你一个链表的头节点 head ,该链表包含由 0 分隔开的一连串整数。链表的 开端 和 末尾 的节点都满足 Node.val 0 。 对于每两个相邻的 0 ,请你将它们之间的所有节点合并成一个节点ÿ…...
Immutable设计 SimpleDateFormat DateTimeFormatter
专栏系列文章地址:https://blog.csdn.net/qq_26437925/article/details/145290162 本文目标: 理解不可变设计模式,时间format有线程安全要求的注意使用DateTimeFormatter 目录 ImmutableSimpleDateFormat 非线程安全可以synchronized解决&a…...
【网络】传输层协议TCP(重点)
文章目录 1. TCP协议段格式2. 详解TCP2.1 4位首部长度2.2 32位序号与32位确认序号(确认应答机制)2.3 超时重传机制2.4 连接管理机制(3次握手、4次挥手 3个标志位)2.5 16位窗口大小(流量控制)2.6 滑动窗口2.7 3个标志位 16位紧急…...
17.[前端开发]Day17-形变-动画-vertical-align
1 transform CSS属性 - transform transform的用法 表示一个或者多个 不用记住全部的函数,只用掌握这四个常用的函数即可 位移 - translate <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta ht…...
LeetCode435周赛T2贪心
题目描述 给你一个由字符 N、S、E 和 W 组成的字符串 s,其中 s[i] 表示在无限网格中的移动操作: N:向北移动 1 个单位。S:向南移动 1 个单位。E:向东移动 1 个单位。W:向西移动 1 个单位。 初始时&#…...
陆游的《诗人苦学说》:从藻绘到“功夫在诗外”(中英双语)mastery lies beyond poetry
陆游的《诗人苦学说》:从藻绘到“功夫在诗外” 今天看万维钢的《万万没想到》一书,看到陆游的功夫在诗外的句子,特意去查找这首诗的原文。故而有此文。 我国学人还往往过分强调“功夫在诗外”这句陆游的名言,认为提升综合素质是一…...
AI模型平台之——ModelScope(魔搭)
ModelScope 是什么? ModelScope 是一个由阿里巴巴达摩院推出的开源模型库和工具集,旨在为开发者提供高效、便捷的机器学习模型和工具。ModelScope 提供了丰富的预训练模型、数据集和工具,支持多种任务和应用场景,如自然语言处理、…...
GIt使用笔记大全
Git 使用笔记大全 1. 安装 Git 在终端或命令提示符中,输入以下命令检查是否已安装 Git: git --version如果未安装,可以从 Git 官方网站 下载并安装适合你操作系统的版本。 2. 配置 Git 首次使用 Git 时,需要配置用户名和邮箱…...
42【文件名的编码规则】
我们在学习的过程中,写出数据或读取数据时需要考虑编码类型 火山采用:UTF-16 易语言采用:GBK php采用:UTF-8 那么我们写出的文件名应该是何种编码的?比如火山程序向本地写出一个“测试.txt”,理论上这个“测…...
Linux网络 HTTPS 协议原理
概念 HTTPS 也是一个应用层协议,不过 是在 HTTP 协议的基础上引入了一个加密层。因为 HTTP的内容是明文传输的,明文数据会经过路由器、wifi 热点、通信服务运营商、代理服务器等多个物理节点,如果信息在传输过程中被劫持,传输的…...
Vue.js组件开发-实现全屏手风琴幻灯片切换特效
使用 Vue 实现全屏手风琴幻灯片切换特效 步骤概述 创建 Vue 项目:使用 Vue CLI 创建一个新的 Vue 项目。设计组件结构:创建一个手风琴幻灯片组件,包含幻灯片项和切换逻辑。实现样式:使用 CSS 实现全屏和手风琴效果。添加交互逻辑…...
数据库、数据仓库、数据湖有什么不同
数据库、数据仓库和数据湖是三种不同的数据存储和管理技术,它们在用途、设计目标、数据处理方式以及适用场景上存在显著差异。以下将从多个角度详细说明它们之间的区别: 1. 数据结构与存储方式 数据库: 数据库主要用于存储结构化的数据&…...
MLM之MiniCPM-o:MiniCPM-o的简介(涉及MiniCPM-o 2.6和MiniCPM-V 2.6)、安装和使用方法、案例应用之详细攻略
MLM之MiniCPM-o:MiniCPM-o的简介(涉及MiniCPM-o 2.6和MiniCPM-V 2.6)、安装和使用方法、案例应用之详细攻略 目录 MiniCPM-o的简介 0、更新日志 1、MiniCPM-o系列模型特点 MiniCPM-o 2.6 的主要特点 MiniCPM-V 2.6的主要特点 2、MiniCPM-o系列模型架构 MiniC…...
【Conda 和 虚拟环境详细指南】
Conda 和 虚拟环境的详细指南 什么是 Conda? Conda 是一个开源的包管理和环境管理系统,支持多种编程语言(如Python、R等),最初由Continuum Analytics开发。 主要功能: 包管理:安装、更新、删…...
Rust 控制流语法详解
Rust 控制流语法详解 控制流是编程语言中用于控制代码执行顺序的重要机制。Rust 提供了多种控制流语法,包括条件判断(if、else if)、循环(loop、while、for)等。本文将详细介绍这些语法,并通过示例展示它们…...
VLC-Qt: Qt + libVLC 的开源库
参考链接 https://blog.csdn.net/u012532263/article/details/102737874...
洛谷 P5146 最大差值 C语言
P5146 最大差值 - 洛谷 | 计算机科学教育新生态 题目描述 HKE 最近热衷于研究序列,有一次他发现了一个有趣的问题: 对于一个序列 A1,A2,…,An,找出两个数 i,j(1≤i<j≤n),使得 Aj−Ai 最大。…...
Zabbix 推送告警 消息模板 美化(钉钉Webhook机器人、邮件)
目前网络上已经有很多关于Zabbix如何推送告警信息到钉钉机器人、到邮件等文章。 但是在搜索下来,发现缺少了对告警信息的美化的文章。 本文不赘述如何对Zabbix对接钉钉、对接邮件,仅介绍我采用的美化消息模板的内容。 活用AI工具可以减轻很多学习、脑力负…...
MySQL数据库环境搭建
下载MySQL 官网:https://downloads.mysql.com/archives/installer/ 下载社区版就行了。 安装流程 看b站大佬的视频吧:https://www.bilibili.com/video/BV12q4y1477i/?spm_id_from333.337.search-card.all.click&vd_source37dfd298d2133f3e1f3e3c…...
书生大模型实战营7
文章目录 L1——基础岛提示词工程实践什么是Prompt(提示词)什么是提示工程提示设计框架CRISPECO-STAR LangGPT结构化提示词LangGPT结构编写技巧构建全局思维链保持上下文语义一致性有机结合其他 Prompt 技巧 常用的提示词模块 浦语提示词工程实践(LangGPT版)自动化生成LangGPT提…...
Spark的基本概念
个人博客地址:Spark的基本概念 | 一张假钞的真实世界 编程接口 RDD:弹性分布式数据集(Resilient Distributed Dataset )。Spark2.0之前的编程接口。Spark2.0之后以不再推荐使用,而是被Dataset替代。Datasetÿ…...
langchain基础(二)
一、输出解析器(Output Parser) 作用:(1)让模型按照指定的格式输出; (2)解析模型输出,提取所需的信息 1、逗号分隔列表 CommaSeparatedListOutputParser:…...