【发布时间】:2019-12-27 14:45:25
【问题描述】:
我想要一个自定义的Dialog 样式,具有另一种背景颜色和圆角边框,因为它看起来比默认的灰色矩形更好。
通过设置Dialog 的Contentpane 的样式,这部分是可能的。问题是,底层对话框样式仍然存在,其中显示了内容窗格。而且似乎Dialog UDID本身无法更改,“Dialog”样式也无法在设计器中被覆盖,也无法被代码覆盖。
Form hi = new Form();
hi.getUnselectedStyle().setBgColor(0xffffff);
Button but = new Button("open dialog");
but.addActionListener(e -> {
Dialog d = new Dialog(BoxLayout.y());
d.setUIID("Container"); // this line has no effect, the outside dialog component is still visible
Style s = d.getContentPane().getUnselectedStyle();
s.setBorder(RoundRectBorder.create());
s.setBgColor(0x00ff00);
s.setBgTransparency(255);
s.setMargin(5, 5, 5, 5); // adding some margin between contentpane and Dailog container, to be more obvious
d.setDisposeWhenPointerOutOfBounds(true);
// title
Label title = new Label();
title.setText("Confirmation");
d.add(title);
// body field with spanlabel info text
SpanLabel bodyLabel = new SpanLabel("Body Text");
d.add(bodyLabel);
// delete button
Button okButton = new Button("Ok");
okButton.addActionListener(e2 -> {
d.dispose();
});
// exit button
Button exitButton = new Button("Cancel");
exitButton.addActionListener(e3 -> {
d.dispose();
});
d.add(GridLayout.encloseIn(2, okButton, exitButton));
d.show();
});
hi.add(but);
hi.show();
在上图中,最外面的深灰色是对话框外的着色区域。绿色是带有预期圆形边框的内容窗格。中间的浅灰色来自我想去掉的Dialog风格。
这个可以吗?
【问题讨论】:
标签: dialog styles codenameone