jcomponent

Change Font at runtime

纵饮孤独 提交于 2019-11-26 22:59:10
Please is there another way how to change Font at runtime as using FontUIResource, for the whole AWT/Swing GUI, without any knowledge / interest about if there are local variables and type of JComponents import java.awt.*; import java.awt.event.*; import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; import javax.swing.plaf.FontUIResource; import javax.swing.plaf.basic.BasicComboBoxRenderer; public class SystemFontDisplayer extends JFrame { private static final long serialVersionUID = 1L; private JFrame frame = new JFrame("Nimbus

jScrollPane can't add component

拜拜、爱过 提交于 2019-11-26 21:54:18
问题 I have a jScrollPane and a button on a form. The button adds a component to the jScrollPane . I'm using a FlowLayout with a center alignment to arrange the components within the jScrollPane . The first component has no problems appearing and is aligned perfectly. When I then hit the button again, nothing seems too happen. When I follow the debugger it shows that everything happens precisely as before. The code that's being executed when the button is clicked: jScrollPane.getViewport().add(new

How to create a custom Swing Component [closed]

一曲冷凌霜 提交于 2019-11-26 17:36:56
问题 I've always wanted to create custom components in Java, or customize existing ones, but my searches never resulted in anything useful. So I decided to ask the StackOverflow community: Where can I find information about customizing Java GUI Components in general? And when I mean customizing, I'm not talking about changing colors, fonts etc. I mean really customize them. Here are two mockup example components: Notes I started this question mainly to find how to create the above two custom

JComponents disappearing after calling mouseClicked()

喜夏-厌秋 提交于 2019-11-26 17:29:17
问题 I am writing a Java GUI program with Swing. The interface looks like this: When the user clicks on one of the pictures on the right hand side, I want a small preview of it to show up in the orange area in the upper left corner. I pull all of the image files from a directory on my computer via a SwingWorker thread. In the SwingWorker's done() method, I add a mouseClicked listener to each object (a TaggableImage object from a class I created. It has a BufferedImage and extends JComponent,

Can't a Swing component be added to multiple containers?

独自空忆成欢 提交于 2019-11-26 16:39:56
I'm trying (testing something else) to add one JButton reference into two JPanels to test it, and it disappears from the first panel it was added to! So, can't a Swing component be added to multiple containers? Thank you in advance. From: http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html : Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second. As you've discovered, you can't share components. However there

JPanel which one of Listeners is proper for visibility is changed

好久不见. 提交于 2019-11-26 14:40:31
Are there some rules, or good/bad experiences with AncestorListener , ComponentListener or HierarchyListener listening for visibility of changes with JPanel and JComponents ? Is one of them better or safer than the others? I would especially like to know about when and how JPanel / JComponent is hidden. Notice the following code contains incorrect Swing rules, like using Thread.sleep(int) , in this case, to allow me to print-out correct order of Listeners in Swing GUI import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.event.ComponentEvent; import java.awt.event

How to get all elements inside a JFrame?

我们两清 提交于 2019-11-26 11:10:31
问题 I have this code to get all the elements I need and do some processing. The problem is I need to specify every panel I have to get the elements inside it. for (Component c : panCrawling.getComponents()) { //processing } for (Component c : panFile.getComponents()) { //processing } for (Component c : panThread.getComponents()) { //processing } for (Component c : panLog.getComponents()) { //processing } //continue to all panels I want to do something like this and get all the elements without

Can't a Swing component be added to multiple containers?

寵の児 提交于 2019-11-26 06:02:24
问题 I\'m trying (testing something else) to add one JButton reference into two JPanels to test it, and it disappears from the first panel it was added to! So, can\'t a Swing component be added to multiple containers? Thank you in advance. 回答1: From: http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html: Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the

JPanel which one of Listeners is proper for visibility is changed

丶灬走出姿态 提交于 2019-11-26 05:56:49
问题 Are there some rules, or good/bad experiences with AncestorListener , ComponentListener or HierarchyListener listening for visibility of changes with JPanel and JComponents ? Is one of them better or safer than the others? I would especially like to know about when and how JPanel / JComponent is hidden. Notice the following code contains incorrect Swing rules, like using Thread.sleep(int) , in this case, to allow me to print-out correct order of Listeners in Swing GUI import java.awt

Swing HTML drawString

点点圈 提交于 2019-11-25 23:50:57
问题 I\'m trying to create some special component for a specific purpose, on that component I need to draw a HTML string, here\'s a sample code: public class MyComponent extends JComponent{ public MyComponent(){ super(); } protected void paintComponent(Graphics g){ //some drawing operations... g.drawString(\"<html><u>text to render</u></html>\",10,10); } } Unfortunately the drawString method seems to be not recognizing the HTML format, it foolishly draws the string just as it is. Is there any way