import java.awt.*;
import javax.swing.*;
public class TestField{
public static void main(String args[]){
MyFrame mFrame = new MyFrame();
mFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mFrame.setVisible(true);
}
}
class MyFrame extends JFrame{
public MyFrame(){
setTitle("TextField");
setSize(400,300);
setLocation(550,350);
MyPanel myPanel = new MyPanel();
getContentPane().add(myPanel);
}
}
class MyPanel extends JPanel{
public MyPanel(){
JLabel label = new JLabel("<html>Hello</html>",SwingConstants.LEFT);
//JLabel label = new JLabel("<html>Hello</html>",SwingConstants.RIGHT);
这个标签组件一开始怎么在中间?设置左边和右边都无用,请问对齐是啥意思?
add(label);
}
}
import javax.swing.*;
public class TestField{
public static void main(String args[]){
MyFrame mFrame = new MyFrame();
mFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mFrame.setVisible(true);
}
}
class MyFrame extends JFrame{
public MyFrame(){
setTitle("TextField");
setSize(400,300);
setLocation(550,350);
MyPanel myPanel = new MyPanel();
getContentPane().add(myPanel);
}
}
class MyPanel extends JPanel{
public MyPanel(){
JLabel label = new JLabel("<html>Hello</html>",SwingConstants.LEFT);
FlowLayout layout = (FlowLayout)getLayout();
layout.setAlignment(FlowLayout.LEFT);
add(label);
}
}
楼主要搞清楚,组件的位置并不是由它自己决定的,而是由它的容器、它的容器的布局管理器决定的,这是原则,设置组件的对齐方式只能影响它内部的子组件,而不能影响它本身在容器里面的位置。
JLabel label = new JLabel("<html>Hello</br>World</html>");
怎么文本没换行?