jlabel

Proper way to use JLabels to update an image

喜欢而已 提交于 2019-11-26 10:03:39
问题 I am creating a GUI, and am fairly new to swing and awt. I am trying to create a gui that, upon launch, sets the background to an image, then uses a method to create a slideshow of sorts. I have attempted it, and I am not attached to the code so I am able to take both revisions and/or whole new concepts. EDIT(9/15/13): I am having trouble with the slideshow, I cant seem to get it to work. Here is my current code. public class MainFrame extends JFrame{ JLabel backgroundL = null; private JLabel

Vertically centering text in HTML table cell in Java JLabel

喜夏-厌秋 提交于 2019-11-26 10:03:24
问题 I have an HTML table (styles with CSS) that is displayed in a JLabel. I would like the contents (a single, short line of text) of the cells to be both horizontally and vertically centered. Horizontal centering is easy, but I cannot seem to center the text vertically. I\'ve tried vertical-align: and valign: with both middle and center arguments. I\'ve looked at several of the tricks, but none of them seemed doable, and the ones I tried didn\'t work. What I have now: Inline (in the <style> tag)

How to remove gap in java swing label of large size

大兔子大兔子 提交于 2019-11-26 10:02:21
问题 in my application I have label which has a font size over 200. This label contains big up and down (irregular)gap. How can I remove it ? This is my code: package Core; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.UIManager; public class LabelDemo extends JPanel { public LabelDemo() {

make a JLabel wrap it&#39;s text by setting a max width

[亡魂溺海] 提交于 2019-11-26 09:46:25
问题 I have a JLabel which has a lot of text on it. Is there a way to make the JLabel have a max width so that it will wrap the text to make it not exceed this width? Thanks 回答1: No. You can use HTML in the label, but then you must hard code the break tag. A better approach is to use a JTextArea and turn wrapping on. You can change the background,foreground, font etc. of the text are to make it look like a label. Note, this answer is outdated as of at least Java 7. As per @darren's answer, you

Why is my JLabel not showing up

核能气质少年 提交于 2019-11-26 06:08:57
问题 I am calling this method called check in one of my abstract classes but for some reason the JLabel (problem) I am adding to the JPanel (panel) is not showing up. Why is this occurring? Any explanations, I am using both the repaint, and validate methods but still nothing shows up. 回答1: The problem you're having is you're blocking the Event Dispatching Thread, prevent the UI from been updated or any new events from been processed... It starts here... for(int i = 0; i < 15; i++) { //... //Check

Does adding a JLabel to a JPanel “hide” the JPanel?

谁说我不能喝 提交于 2019-11-26 06:08:44
问题 If I have a few JPanels in a GridLayout, each one with a MouseAdapter, and then create JLabels (with text) and add to each one of the JPanels. Note the JLabels have no listeners. If I render this and try to click on a JPanel, or, ultimately try to click on the JLabel, will the MouseAdapter register that as an event? Basically I want the JPanels to register events and the JPanels to just display text on-top of the JPanels. Also, the panels have background color. If the JLabel does \"hide\" the

Can I have a textfield inside a label?

拈花ヽ惹草 提交于 2019-11-26 05:54:41
问题 What I would like to do is display the following in a form: Open [15] minutes before class Where [15] is a text-field. Is this possible? 回答1: Use a 'composite component' by adding the required parts to a JPanel . E.G. import java.awt.FlowLayout; import javax.swing.*; class TimeBeforeClass { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JPanel gui = new JPanel(new FlowLayout(FlowLayout.LEFT, 3,3)); gui.add(new JLabel("Open")); gui.add

JLabel images array

蓝咒 提交于 2019-11-26 05:21:36
I am trying to load the same jlabel stored image twice into a gridlayout panel, however instead of creating two instances of the image, the image is only displayed once then moved. How can I store the same JLabel position in the pieces array into more than one JLabel in the boardLabels array. Thanks :) public static JPanel boardPanel = new JPanel(new GridLayout(4, 0)); public static JLabel pieces[] = new JLabel[2]; private static JLabel[] boardLabels = new JLabel[4]; public MainFrame() { pieces[0] = new JLabel(new ImageIcon(System.getProperty("user.dir") + "/images/piece1.png")); pieces[1] =

Setting print size of a jLabel and put a jRadiobutton on the print

牧云@^-^@ 提交于 2019-11-26 04:56:00
问题 I have a jLabel with an Icon that I should print. However, I can\'t get the jLabel\'s icon to full size. Here\'s some of the code that I think that it is affecting the print size. public static void printComponentToFile(Component comp, boolean fill) throws PrinterException { Paper paper = new Paper(); paper.setSize(8.3 * 72, 11.7 * 72); //here paper.setImageableArea(18, 18, 100, 300); //and here PageFormat pf = new PageFormat(); pf.setPaper(paper); pf.setOrientation(PageFormat.LANDSCAPE);

How to change the size of the font of a JLabel to take the maximum size

断了今生、忘了曾经 提交于 2019-11-26 04:45:24
问题 I have a JLabel in a Container. The defaut size of the font is very small. I would like that the text of the JLabel to take the maximum size. How can I do that? 回答1: Not the most pretty code, but the following will pick an appropriate font size for a JLabel called label such that the text inside will fit the interior as much as possible without overflowing the label: Font labelFont = label.getFont(); String labelText = label.getText(); int stringWidth = label.getFontMetrics(labelFont)