awt

triple buffer heavy flickering

穿精又带淫゛_ 提交于 2019-12-04 18:34:44
Shouldn't triple buffering and Canvas be an optimal solution for passive rendering? I've just wrote this java code that displays a circle. If I leave bufferstrategy to 3, it flickers so much. If I turn it down to 2 or 1 it's ok. Maybe I'm doing something wrong? public void run(){ while (running){ update(); draw(); } } public void update(){ } public void draw(){ BufferStrategy bs = getBufferStrategy(); if (bs==null){ createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.BLACK); g.fillOval(30, 30, 20, 20); g.dispose(); bs.show(); } and this is the JFrame class

Adding fonts to Swing application and include in package

耗尽温柔 提交于 2019-12-04 16:51:04
问题 I need to use custom fonts (ttf) in my Java Swing application. How do I add them to my package and use them? Mean while, I just install them in windows and then I use them, but I don't wish that the usage of the application will be so complicated, it`s not very convenient to tell the user to install fonts before using my application. 回答1: You could load them via an InputStream : InputStream is = MyClass.class.getResourceAsStream("TestFont.ttf"); Font font = Font.createFont(Font.TRUETYPE_FONT,

how to get mouse position of a Java application?

余生颓废 提交于 2019-12-04 16:31:45
documentDOM.addEventListener("click", new EventListener() { public void handleEvent(Event evt) { if (evt.getType().equals("click")) { System.out.println("hello"); MouseEvent mouseIvent = (MouseEvent) evt; int screenX = mouseIvent.getXOnScreen(); int screenY = mouseIvent.getYOnScreen(); System.out.println("screen(X,Y) = " + screenX + "\t" + screenY); } } }, true); I need to locate a specific pixel location on my Java application. This Java application can be windowed or maximized window. My code somehow doesn't return the integers. this event does fire as hello message is spit out. The key is

jTable right-click popup menu

独自空忆成欢 提交于 2019-12-04 15:56:30
问题 I have a SQL database and I am working on a program that will allow me to add/delete/modify records. I already managed to add records I am working on editing/deleting them. I want to display the existing records in a table so I am using jTable. I found some code online and modified it to pull the records and display them in a jtable but i dont know how to code the rightclick and display a popup menu. In that popup menu I want to display options such as delete record and modify record. This is

Two Different Panels in One Frame - Java

不打扰是莪最后的温柔 提交于 2019-12-04 15:47:16
I have a question. I have one main frame, and to the left i have a sidebar with menus. My question is, is it possible to make another panel within the main frame, so that if menu1 is clicked, the related contents should be displayed to the second half of the main frame, and when other menus are pressed then obviously the relevant stuff according to what is selected. its a bit hard to explain, sorry. Has anyone got an idea, whether that is possible in Java with Eclipse? yes this's pretty possible you have look at CardLayout , this LayoutManager could be provide the simple way how to implement

Graph visualization libraries for SWT/AWT

拥有回忆 提交于 2019-12-04 14:51:33
问题 Is there a mature, solid open-source graph visualization library implementation for SWT or AWT (I am referring to sets of vertices connected with edges, not charts and diagrams)? Which one do you use/recommend? I saw Zest for SWT, but could not find a Maven repository for it. Thank you. 回答1: I recommend Prefuse: http://prefuse.org/ 回答2: Have a look at JUNG ( http://jung.sourceforge.net/ ) 回答3: If you don't want to use Zest (which I prefer), there is still Draw2D : Draw2D Also, there is a good

When you use Frame or JFrame in Java? [duplicate]

时间秒杀一切 提交于 2019-12-04 13:46:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What is the difference between swing and awt? I often see that JFrame is used a lots. But sometimes, I also see that programmer use Frame in their example. So could you tell me the advantages/disadvantages of them? 回答1: Well let me break it up for you.............. Before jumping into Frame Vs JFrame, let me explain you about AWT and Swing. AWT : - It has a Platform Dependent Look and Feel . - So it uses the

How to handle the height of the tab title in JTabbedPane

依然范特西╮ 提交于 2019-12-04 13:07:49
I am preparing a window with some horizontal tabs using JTabbedPane, Tabs And window are prepared properly. Now I need to setup these tabs in level basis, based on my requirement (My logic returns integer value based on that I need to setup levels ). Levels look like : Can you please advise? Just the sight of screenshot: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TabHeightTest { public JComponent makeUI() { JTabbedPane tabbedPane = new JTabbedPane( JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); tabbedPane.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI(

Drawing a nice circle in Java

▼魔方 西西 提交于 2019-12-04 12:15:40
问题 I'm using Java Graphics and I keep getting "ugly" circles. Here's what my Java program makes And here's the same thing being made in Matlab I think it is clear that the Java one is not as "nice" looking as the Matlab one, particularly on the edges of the circle. Note that this has nothing to do with the resolution...these images are practically the same size. Also note that I am already setting rendering hints. Here's a stand alone with a Main function you can run to test this out. package

Android alternative to java.awt (BufferedImage and Raster)

99封情书 提交于 2019-12-04 12:03:54
问题 for my final year project I am developing an android app that can capture the image of a leaf and identify what type of tree it came from. I have a nearly completed PC version (developed in java) and i am starting the process of porting it to android. Although BufferedImage and Raster make up a key part of my program, this is a problem because java.awt is missing in android, so this means i have to alter the library. I am using a library that was developed by my lecturer, the method below