Tag: jlabel

JLabel – 将更长的文本显示为多行?

所以说我想要在JLabel显示一条非常长的行。 我该怎么做? 目前,更长的线路出现了: 我必须调整窗口大小以查看完整的文本。 当文本几乎达到我的JFrame的宽度时,我怎样才能使它有换行符? 我不确定这里是否需要任何代码才能回答这个问题,但仍然: 我的框架属性: frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(450, 400)); frame.setLocation(new Point(400, 300)); frame.setLayout(new BorderLayout()); 我要修改的标签: question = new JLabel(“Question:”); question.setFont(new Font(“Serif”, Font.BOLD, 15)); question.setHorizontalAlignment(JLabel.CENTER); 编辑:更多细节: 我正在从文件中读取行,然后显示它们。 线条的大小不固定,所以我不知道放在哪里。 编辑2: 我最终使用了JTextArea 。 private JTextArea textAreaProperties(JTextArea textArea) { textArea.setEditable(false); textArea.setCursor(null); textArea.setOpaque(false); textArea.setFocusable(false); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); return textArea; }

如何从文件夹中的图像将图标设置为JLabel?

每当从JComboBox中选择一个项目时,我都试图从图像文件夹中将图标设置为JLabel。 JComboBox中的项目名称和文件夹中图像的名称相同。 因此,无论何时从JComboBox中选择项目,都应将具有相同名称的相应图像设置为JLabel的图标。 我想做这样的事情。 private void cmb_movieselectPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt){ updateLabel(cmb_moviename.getSelectedItem().toString()); } protected void updateLabel(String name) { ImageIcon icon = createImageIcon(“C:\\Users\\xerof_000\\Pictures\\tmspictures\\” + name + “.jpg”); if(icon != null){ Image img = icon.getImage(); Image newimg = img.getScaledInstance(lbl_pic.getWidth(), lbl_pic.getHeight(), java.awt.Image.SCALE_SMOOTH); icon = new ImageIcon(newimg); lbl_pic.setIcon(icon); lbl_pic.setText(null); } else{ lbl_pic.setText(“Image not found”); lbl_pic.setIcon(null); } } protected static ImageIcon createImageIcon(String path) […]