jcomponent

Prevent Java from repainting the content of a JPanel while updating

一个人想着一个人 提交于 2019-11-28 14:20:26
I have a JPanel which contains a lot of child components. While updating\adding new components to the parent JPanel I'd like to prevent it from repainting, how can this achieved? Try RepaintManager.currentManager(component).markCompletelyClean(component) . It will prevent the component from repainting. You might need to do this after each time you add new components. setVisible(false) update setVisible(true) you could try by using setIgnoreRepaint(boolean value) but it's a typical swing feature that can or cannot work (mainly because it depends from AWT so you never know). Otherwise you could

Get a component from a JTextPane through javax.swing.text.Element?

好久不见. 提交于 2019-11-28 13:46:56
I am using a JTextPane to display characters and symbols, where the latter are represented by custom painted JComponents . For example, the text pane might show something like this: The text pane is user editable and it is allowed for the user to add more symbols via a button at any position and as a replacement for selected text. I do this via the JTextPane.insertComponent() method. At some point in the application I need to know what is currently being displayed in the text pane, and by that I mean not only the entered text, but also the exact components contained within. I went through

Layering Objects (That extend JComponet) on JApplet

坚强是说给别人听的谎言 提交于 2019-11-28 10:28:48
问题 I currently have a JApplet within which I add two objects that both extend JComponet. Object A is basically a large square and object B is a small square, I need Object B to always be in front of Object A, however I cant work out how to set layering within the JApplet to do this. Current I am using the follow code, which adds both the items and displays them how I want however sometimes Object A is front of Object B. public void init() { add(myapplet, BorderLayout.CENTER); resize(200, 400); B

jScrollPane can't add component

蓝咒 提交于 2019-11-28 01:26:15
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 Component()); This is how I setup the FlowLayout on the Viewport of the jScrollPane : jScrollPane

Easier way to make a paint application in java?

一世执手 提交于 2019-11-27 22:55:14
问题 So basically I have some code I was working on a couple of days ago that is kind of like Paint, which allows you to essentially draw on the screen using the mouse. I kind of discovered this property by accident, and I realized that it is really inefficient and i'm wondering if there is a more practical way to do this. There isn't really any reason to give all of my code, but here are the important parts private static void createAndShowGui() { SimpleDraw mainPanel = new SimpleDraw(); MenuBar

Placing a JLabel at a specific x,y coordinate on a JPanel

Deadly 提交于 2019-11-27 21:32:34
I'm trying to place a series of JLabels at specific X and Y coordinates on a JPanel (and set its height and width, too). No matter what I do, each label winds up immediately to the right of the previous label and has the exact same size as all of the others. Right now, my Jpanel is in a Grid Layout. I've tried Absolute Layout (illegal argument exception results), Free Design (no labels appear), Flow Layout (everything just gets squeezed to the center), and a few others. Not sure what I need to do to make this work. Can anyone help? Thanks! JLabel lbl1 = new JLabel("label 1"); JLabel lbl2 = new

Placing a JLabel at a specific x,y coordinate on a JPanel

时光总嘲笑我的痴心妄想 提交于 2019-11-27 19:12:02
问题 I'm trying to place a series of JLabels at specific X and Y coordinates on a JPanel (and set its height and width, too). No matter what I do, each label winds up immediately to the right of the previous label and has the exact same size as all of the others. Right now, my Jpanel is in a Grid Layout. I've tried Absolute Layout (illegal argument exception results), Free Design (no labels appear), Flow Layout (everything just gets squeezed to the center), and a few others. Not sure what I need

JPanel not listening to key event when there is a child component with JButton on it

六眼飞鱼酱① 提交于 2019-11-27 08:28:41
问题 I'm working on a map editor for my college project. And I had a problem that the map panel is not listening key event while it should. This happens when I add a ToolBarPane (which extends JPanel) with JComponent such as JButton, JComboBox that implements ActionListener on it AND the map panel (which extends the JPanel) together on to the Frame (I used BorderLayout). I have System.out.println statement to test if the key press is received, and it's not printing, if I remove the ToolBar, the

How to create a custom Swing Component [closed]

≯℡__Kan透↙ 提交于 2019-11-27 07:04:52
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 components. But then I realized that there isn't a general question about hacking swing components. So I

How to get all elements inside a JFrame?

家住魔仙堡 提交于 2019-11-27 04:24:45
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 need specefy all the panels names. How I do this. The code below don't get all the elements. for