swing

JComponent is not visible, anyone knows why?

Here's my JFrame code: public static void main(String[] args) { JFrame jf = new JFrame(); jf.setSize(600,600); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyCustomWidget widget = MyCustomWidget.createWidget(400, 400); widget.setVisible(true); // just to set x and y widget.setLocation(40, 40); jf....

Java Swing or Windows Forms for desktop application?

I am writing a fat client application that I would ideally like to be cross-platform, but may settle for Windows-only based on the following: I am much stronger in C# than Java (though I have a few years Enterprise Java experience) I haven't done much with either Windows Forms or Java Swing, just toy apps for each, though I'm more comf...

Buttongroup in java?

How to add contents of button group in to netbeans using radio buttons? how to get selected item of radiobuttons in buttongroup? ...

Get the image from the title bar of JDialog

I need to get the image from the title bar of the JDialog. Is there any way to get the image from the JDialog, there is no getIconImage() method, i tried getIconImages() but it doesnt works. ...

How to add new component to the panel at run time

I want to add JCombobox to the panel at run time, I don't have idea about this, so please if you have any idea about this suggest me. ...

Floating DIVs in a JTextPane

I have an HTML file that I am loading into a JTextPane which contains two DIVs I am trying to show side-by-side (using CSS float). Whatever I try, though, does not work. The instructions element is displayed below the title element, always. I've tried adjusting the widths as well. Does JTextPane not support this CSS property - must I use...

java swing resize

hello, I am writing a library where i am passed in a Container (usually JPanel) and have an xml specification for different controls, their locations, size and other attributes. i have to create those controls at runtime and add it to the component. What's a good way to handle resizing of the parent Container? ...

Java swing and expand window/textarea

In the following example, I want to be able to expand the text area when I maximize or minimize the window. Right now, the textarea is set to the cols/rows. If I hit maximize, the text area should expand as the window expands. Note: this is kind of a pseudo example. I may add more components which is why I used the GridBagLayout mana...

Checking for a series of clicks in java swing GUI

I'm working on a GUI for a chess game and I was wondering if there's any way to check for a series of clicks, for example: user clicks on jPanel THEN user clicks on another jPanel that exists in valid move array. I know I could use a variable to store some kind of state like "isSquareClicked = true" or something but I'd rather not unless...

Window resize event?

Hi all! I'm writing a simple painting program using java, and I want some method to be called whenever the JFrame component is resized. But I can't find any method like windowResizedListener or an event like windowResizedEvent. what can I do?! ...

Placing a button on panel`s border

Is there any way to create border class with buttons on it? Like this: example One important condition - buttons have to be aligned to border position, because panel can change its size. So imho LayeredPane don`t fit for this - there is no any aligment on it. Have one idea - to imitate buttons: create my class for panel override pain...

Use String list as source of Combo Box

I wanted to use a String list as a source of various options in jComboBox in Java. Can you tell which method to use Thanks ...

How to change the size of the graphics

I have Java applet to draw an array (just some rectangle one after another). When user select to create array of size n, it will draw n rectangles connected together. When n gets bigger, the graphics get bigger, but since i use JPanel to draw the array, and JPanel won't scroll, i have to add that JPanel into a JScrollPane, but still it ...

Java Desktop application: SWT vs. Swing

Hey, I'm a web developer at day and thinking about building my first real desktop application. The idea is to build a tool that automates a very repetitive task in a web application where no API is available. I know I want to use Java. I used it before for web stuff, know the syntax pretty well and want the application to be cross pla...

JScrollPane for a panel containing a set of labels with BoxLayout

Hi All, I'd like to use a JScrollPane for a panel which has an arbitrary list of labels in it using box layout. I'm trying to get it so that the scrollbar would appear if there were too many items (labels) to display. I tried adding a JScrollPane to the panel and then add the labels but then I don't see any scroll bar. Any ideas? T...

Strange colors +Java +JColorChooser

import javax.swing.*; import java.awt.*; public class Fr extends JFrame{ Fr(String s){ super(s); setSize(200,300); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paint(Graphics gr){ gr=getGraphics(); gr.fillRect(50, 50, 20, 20); } pub...

How to recognise mouseDragged and mousePressed events in one listener?

In following code, mouseDragged is not recognized. What do I do wrong? addMouseListener(new MouseInputAdapter() { @Override public void mouseDragged(MouseEvent e) { ... } @Override public void mousePressed(MouseEvent e) { ... } }); ...

Why is object indended using Swing BoxLayout

Can someone explain why the text "Options" is indented here? This looks like a bug to me in BoxLayout. TIA import javax.swing.*; import java.awt.*; public class BoxLayoutIssue { public static void main(String[] args) { JFrame f = new JFrame(); f.setSize(240, 250); f.setDefaultCloseOperation(JFrame.EXIT_ON...

swing: setting cursor on JDialog

Hi, I have a JPanel inside a dialog. A MouseListener listens to mouse movements, and when the mouse is on a specific location, I call setCursor() on the panel to change the cursor. This all works well, untill I open another dialog from within this dialog and close it again. (For example: a warning message (JOptionPane), or a new custom...

multiple JFrames

im creating a java application with netbeans. i have two jframes for login and the main application. what i want to do is to load the login jframe at runtime, then load the main application jframe when user authentication is correct. the instance of the login jframe must be destroyed after the main application jframe has already loaded. ...