是否有工具来生成Spring应用程序上下文的图/图?
该工具还应考虑注释驱动配置(如@Autowired).
该工具可以通过在运行时"转储"BeanDefinitions来生成依赖关系图.即我不需要该工具进行静态代码分析.
让我们有以下类层次结构:
public class MyType {
}
public class MySuperclass<T extends MyType> {
protected Map<String, String> myMap = new TreeMap<String, String>();
protected String myMethod(String s) {
return myMap.get(s);
}
}
public class MySubclass extends MySuperclass {
@Override
protected String myMethod(String s) {
return myMap.get(s); // <-- compilation error
}
}
Run Code Online (Sandbox Code Playgroud)
为什么在overriden方法中存在编译错误MySubclass?错误消息是"类型不匹配:无法从对象转换为字符串".
有趣的是,如果我MySuperclass在MySubclass定义中定义泛型类类型,则编译错误消失了:
public class MySubclass extends MySuperclass<MyType> {
@Override
protected String myMethod(String s) {
return myMap.get(s);
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释这种行为吗?我认为这是一个Java编译器错误.
我正在使用jdk1.6.0_24.
我先来描述下图:

我希望绿线突出显示的所有字符都打印在一列中.
String的字体是monospaced Courier New.但是,似乎空格字符不会打印为等宽字体(请参阅"虚线"线与开头的空格字符行).
要打印字符串,我在JTextPane组件上使用标准Java Print Service API:
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(myTextPane);
pj.print();
Run Code Online (Sandbox Code Playgroud)
据我所知,Java Print Service API实际上调用了myTextPane的paint()方法.因此,预览应与String的打印版本完全相同.
但事实并非如此.预览似乎没有误解等宽空间字符(参见最后一张图).预览看起来与我想要打印的文本完全相同.

有关如何强制JavaPrintServiceAPI正确打印等宽字符空间字符的任何建议吗?
有没有办法转换String
"m1, m2, m3"
Run Code Online (Sandbox Code Playgroud)
以下
"m1/build, m2/build, m3/build"
Run Code Online (Sandbox Code Playgroud)
只能通过使用String.replaceAll(regex, replacement)方法?
到目前为止,这是我最好的尝试:
System.out.println("m1, m2, m3".replaceAll("([^,]*)", "$1/build"));
>>> m1/build/build, m2/build/build, m3/build/build
Run Code Online (Sandbox Code Playgroud)
如您所见,输出不正确.但是,在Linux的sed命令中使用相同的正则表达式可以提供正确的输出:
echo 'm1, m2, m3' | sed -e 's%\([^,]*\)%\1/build%g'
>>> m1/build, m2/build, m3/build
Run Code Online (Sandbox Code Playgroud) 当我运行下面的示例代码时,JTextArea的宽度是固定的(100px),而其高度是动态调整的,因为我在其中键入了一些文本.
例如,我从这开始:
--------------------
| some text |
--------------------
Run Code Online (Sandbox Code Playgroud)
当我输入更多文本时,JTextArea的高度会扩展,以便在保留宽度的同时适合内容:
--------------------
| some text, some |
| other longer text|
| etc... |
--------------------
Run Code Online (Sandbox Code Playgroud)
如何加倍JTextArea的宽度?当我这样做时,通过改变preferredSize高度不再是动态的.
public class TestTextArea extends JFrame {
public static void main(String[] args) {
new TestTextArea().setVisible(true);
}
public TestTextArea() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0,0,800,600);
setContentPane(createPane());
}
protected Container createPane() {
JTextArea textArea = createTextArea();
// ------------------------------------------
// UNCOMMENT TO DOUBLE THE WIDTH OF JTextArea
// Dimension oldPrefSize = textArea.getPreferredSize();
// Dimension newPrefSize = new Dimension(oldPrefSize.width * 2, oldPrefSize.height); …Run Code Online (Sandbox Code Playgroud) 问题
我们的独立Swing应用程序在某些特定事件(按钮单击等)上显示模态JDialog.该对话框包含一些其他Swing组件(JLabel,JButtons,...).而不是通过JDialog.setBounds(...)我们调用的方法JDialog.pack()(或者方法隐式调用它)显式设置其维度.通过方法计算的维数总是不变的(例如300x100像素.)不幸的是,有时可见对话框的实际维度是1x1 px().JOptionPaneshowDialog(...)pack()JDialog.getSize().equals(new Dimension(1, 1))
JDialog初始化
我们JDialog在应用程序中初始化s 有两种方法.我们检查了两个初始化方法总是从EventDispatchThread调用.
第一种方法
我们只创建一个ADialog其子类的实例JDialog.这是我们的初始化过程的片段:
ADialog dialog = new ADialog();
dialog.setContentPane(content);
dialog.setVisible(true);
Run Code Online (Sandbox Code Playgroud)
这是我们的ADialog实施:
public class ADialog extends JDialog implements ComponentListener {
public JfosDialog(Frame owner) {
super(owner);
init();
}
private void init() {
super.addComponentListener(this);
}
@Override
public void componentShown(ComponentEvent e) {
// Calling pack() at this place is really weird, but we
// have to do …Run Code Online (Sandbox Code Playgroud) 是否可以使用一个明确定义其类的类型的构造函数编写泛型类?
这是我尝试这样做的:
import javax.swing.JComponent;
import javax.swing.JLabel;
public class ComponentWrapper<T extends JComponent> {
private T component;
public ComponentWrapper(String title) {
this(new JLabel(title)); // <-- compilation error
}
public ComponentWrapper(T component) {
this.component = component;
}
public T getComponent() {
return component;
}
public static void main(String[] args) {
JButton button = new ComponentWrapper<JButton>(new JButton()).getComponent();
// now I would like to getComponent without need to cast it to JLabel explicitly
JLabel label = new ComponentWrapper<JLabel>("title").getComponent();
}
}
Run Code Online (Sandbox Code Playgroud) 我像这样修改getMessage()我TestClass的Javassist的方法体:
ClassPool cp = new ClassPool(true);
CtClass ctClass = cp.get("my.test.javassist.TestClass");
CtMethod ctMethod = ctClass.getDeclaredMethod("getMessage");
ctMethod.setBody("{ return \"Hello from javassist\"; }");
ctClass.toClass();
TestClass c = new TestClass();
System.out.println(c.getMessage());
Run Code Online (Sandbox Code Playgroud)
它运作良好.但是,如果我删除ctClass.toClass()方法调用,则主体替换不起作用.为什么?
我应该如何正确地替换我getMessage()方法的主体?我做得对吗?
我有一个基于材料设计指南的标准“CollapsingToolbarLayout”实现。
通过下面的设置,我能够实现图片上描绘的行为:
<CoordinatorLayout ...>
<AppBarLayout ...>
<CollapsingToolbarLayout
app:layout_scrollFlags="scroll|enterAlways"
...>
<Toolbar
app:layout_collapseMode="pin">
</Toolbar>
<MyCustomContent01 ... />
</CollapsingToolbarLayout>
</AppBarLayout>
<MyCustomContent02 ... />
</CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
如何实现以下行为?:
换句话说:如何在保留步骤 4 的条件的同时摆脱步骤 3?
对我来说,关于这个主题的最好的文章似乎是这篇文章,但是所提供的配置都不符合我的需求。
尝试一:
<CollapsingToolbarLayout
app:layout_scrollFlags="scroll|enterAlways"
...>
Run Code Online (Sandbox Code Playgroud)
尝试二
<CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed"
...>
Run Code Online (Sandbox Code Playgroud)