953 Posted Topics
Re: [crossposted](http://stackoverflow.com/questions/17130260/java-swing-getting-values-from-dynamically-generated-jtabbedpane) | |
Re: > i have a problem in logic of swapping in java. That is how to swap no. of buttons with mouse click i am not getting the proper code for that..,please, can anybody there 2 help me out..! thnks - whats **swapping in java** - whats hidden in **how to … | |
Re: - change **null** from **int response = JOptionPane.showConfirmDialog(null ...** to real parent, any (J)Component that returns true from isDisplayable(), means that is already visible on the screen, then **JOptionPane** will be centered to this Point - JOptionPane is only the JDialog, then there is possible to moving with locationOnScreen, - … | |
Re: - all discusion about **KeyListner** is wrong, caused a few another side effects from usage of wrong **Listener** - there no reason call for **repaint()**, why repeating, supply methods implemented in API, all those notifiers are implemented and correctly - not, never to use **KeyListener** for **Swing JComponents**, this **Listener** … | |
Re: - remove *panelOne.setSize(300,300);* - remove *super.setSize(300,300);* use *pack()* instead - remove all *super.Xxx*, create an *local variable for JFrame* - *JPanels* dimension (inside *JScrollPane*) must be greater than rectangle from *JScrollPane* (basic property, reason why *JScrollPane* is there), otherwise *JScrollBar* isn't visible | |
Re: [crossposted & answered](http://www.coderanch.com/t/613486/GUI/java/Showing-JTree-scroll-panes) | |
Re: **So far I have managed to use a TableModelListener to respond to the changing cell values** - don't to use Model Listeners to change Model, - this is Model_To_View notifier, carrefully with that, result can be endless loop, - override setValueAt for computations inside XxxTableModel **What I wish to do … | |
Re: JTextArea.append() ???, not clear from description(s), answers, nor from code | |
Re: 1. use JApplet not Applet (I'd suggest to use JFrame instead) 2. put there JPanel ant to override paintComponent instad of paint() 3. 1st. code line should be super.paintComponent(), otherwise all painting will be cumulating 4. rest is described in Oracle tutorial [Performing Custom Painting](http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html) | |
Re: [crossposted](http://stackoverflow.com/questions/16777758/how-to-load-jpanel-in-a-jframe-using-button-click-netbeans) | |
- Please how is possible (probably dirty hack) to create [How to Create Translucent and Shaped Windows](http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html) - undecorated container (returns *java.awt.IllegalComponentStateException: The frame is displayable.*) - change Look and Feel for (returns *AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated*) - by using code from linked official tutorial . import java.awt.*; … | |
Re: 1. there are two ways - by moving with derived JScrollBar from JScrollpane - by moving with JViewport to desired Rectangle 2. both are based on Rectangle from JComponent.getBounds(), where JComponent.getBounds() is required JComponent to be visible in JViewport 3. easiest of ways is moving with JViewport e.g. **JScrollPane#scrollRectToVisible(JComponent.getBounds())** | |
Re: @bguild answers here going wrong directions, please to review that, from end to the start, @CoilFyzx please whats your goal, there are simpler ways, by using JTable and/or with another, both JTables can has the same TableModel, depends of your final idea, used notifiers and Listeners | |
Re: @stultuske agree with, use CardLayout instead of replacing JPanels programatically | |
Re: *Sometimes I update my web service JAR by deleting the old one*, are you tried to use JWS(tJWS not clear from your description) | |
Re: [looks like as we are](http://en.wikipedia.org/wiki/Composition_over_inheritance) mixing [composition with inheritance](http://www.javaworld.com/jw-11-1998/jw-11-techniques.html) | |
Re: 1. add JPanel to JFrame, override paintComponent for JPanel, custom painting is done for container only 2. JPanel must be focusable, setFocusable(true), otherwise isn't possible to catch events from KeyListener 3. override getPreferredSize, then all coordinates for Oval could be calculated from getHeight/getWeight only, works after JFrame is resized too … | |
Re: JTable has the similair structure as - Database (column names and row) - original xml structure is about (similair to) databases or Tree structure - plain csv file (acceptable by MsExcell as well), there are a few codes how to export JTable to MsExcel (JTableHeader and rows too), its only … | |
Re: agreed with @stultuske, another points, depends of - JButtons arrays is created once time or dynamically on runtime - not sure if GBC (this ways) works correctly (from posted codesnipped), maybe use GridLsyout - no idea whats **courseBtnArray.add(new JButton("Course 1"));** and **courseBtnArray.add(new JButton("Course " + (i + 2)));**, why JButtons … | |
Re: there are see two issues 1. decimal separator is dot programming languages 2. use Numbers instance with Currency formatter, then output to the Java GUI will be 10,00, but stored with dot internally | |
Re: 1. **model = new DefaultListModel()**; should be declared as local variable or separate class 2. **List = new JList( this.observerlink.getlist() )**; a) **List** is reserved Java word for **util.List** and **awt.List** ....change that to **myList** (Java is CaseSensitive, for more infor to search for Java naming convention) b) **myList** should … | |
Re: @jalpesh_007 - wrong, not true at all - [Top-Level Containers](http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html) are bases on properties came from Native OS, - simple [**Top-Level Containers** never ever are** GC'ed**](http://stackoverflow.com/questions/6309407/remove-top-level-container-on-runtime) - then **setVisible(false)** == **dispose()** - there are two proper ways a) [CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) b) (if is there real reason) then to use **JDialog** and … | |
Re: - [crossposted](http://www.coderanch.com/t/607931/GUI/java/removing-image-background-color-java) - again don't paint to the container directly, use JComponent, JPanel, JLabel - prepare an Image in SW that can do that, is designated for, save as png, put ImageIcon to the JLabel | |
![]() | Re: - [crossposted](http://stackoverflow.com/q/15565757/714968) - create an [SSCCE](http://sscce.org/), short, runnable, compilable, otherwise anyone can ended with **"Whats ModelEquivalent"** ![]() |
Re: - never to paint to the Top-Level Containers, use JPanel instead - prepare all Objects to the Array (if there are more than one element) - use paintComponent inastead of paint | |
Re: - in Swing are implemented methods for displaying Icon / ImageIcon in JComponents APIs - put ImageIcon / Icon (create an loval variable) to the JLabel.setIcon(logo) directly, - for this job isn't required to play BufferedImage - another issue is about layout contens properly | |
Re: @David, probably not an answer - why reinvent the wheel (as you know very well I'm always against...), use standard code made by Sun or SwingX (has issue with Carret & Highlighter) - maybe not to use KeyBindings or KeyListener, job for AWTEventListener (key & mouse events) - I miss … | |
Re: - agreed with @JamesCherrill about util.Timer, Executor (black hole, dirty and empty API), notice about EDT - [for endless loop I'd be to use util.Timer invoked Executor, and executor to invoke SwingWorker (same as Executor, the same black hole, dirty API)](http://stackoverflow.com/a/7049095/714968) - every IDE has implemented one_click to JProfiler | |
Re: - use JFormattedTextField for number instance (similair code example in Oracles tutorial about how to use JFormattedTextField), or JSpinner - there are two ways (JTextComponents returns Document, model for JTextComponents, use getDocument rather than getText) 1. use DocumentListener (in the case that all changes from JTextComponents will going outside) 2. … | |
Re: **can i change toggle button's state to another (play state to pause),by clicking another button(stop)** - **JToggleButton.setSelected(true / false)** (inherits from **JCheckBox** / **JRadioButton**, has two states) - use **ItemListener** (returns **SELECTED** / **DESELECTED**, then easy to test), otherwise you have to test for **isSelected()** | |
Re: use NumberFormat or DecimalFormat for number instance, set proper RoundingMode and decimal places if needed for example import java.math.RoundingMode; import java.text.NumberFormat; import java.util.Formatter; public class round { public static double roundTo2Places(double value) { assert value >= Long.MIN_VALUE / 100 && value <= Long.MAX_VALUE / 100; long digits = (long) (value … | |
Re: [crossposted](http://stackoverflow.com/questions/15211134/blocking-thread-when-progressbar-is-running) | |
Re: - **JPanel** has implemented **FlowLayout** in API - **FlowLayout** accepting only **PreferredSize** that came from **JComponents** back to the container (**JPanel** in this case) - **Painting in Swing**, **Graphics(2D)** by default never returns any **PreferredSize**, [have to override this **Dimension**](http://stackoverflow.com/a/11071471/714968) - don't forget to set coordinates to the **getHeight/Weight**, instead … | |
Re: have to testing with **if (jSlider1.getValueIsAdjusting()) {** inside **ChangeListener** | |
Re: harinath_2007 wrote **Whenever the text in the textarea fills up completely , i want the scrollbar to scroll down.** there are two ways: 1st. way JTextArea textArea = new JTextArea(); DefaultCaret caret = (DefaultCaret)textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); 2nd. way - get the **JScrollBar** from **JScrollPane** as local variable, - add **DocumentListener** to … | |
Re: there are two ways - use [ButtonModel](http://docs.oracle.com/javase/7/docs/api/javax/swing/ButtonModel.html), there are **isArmed()**, **isRollover()**, **isSelected()**, returns **action**, **memonic** and **name** too - but and or with [JButton#get/putClientProperty(Object key, Object value)](http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#putClientProperty%28java.lang.Object,%20java.lang.Object%29), ther you can multiple description in String, number of keys isn't limited somehow | |
Re: AFAIK not possible, without JNI/JNA, otherwise Font, Color, MessageType is based on resources came from Native OS, in the case that you'll to change theme in OS, then will be changed these properties too, accesible frome Win32, Net, C++, e.i. | |
Re: - everything depends of [JTable.setSelectionMode](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#selection) - **To retrieve the current selection, use JTable.getSelectedRows which returns an array of row indexes, and JTable.getSelectedColumns which returns an array of column indexes. To retrieve the coordinates of the lead selection, refer to the selection models for the table itself and for the table's … | |
**short version** --> not able to upvote answers **long(er) version** --> I tried this action to the Java forum, in several threads and from two separate PC's logged under my user | |
Re: [crossposted](http://stackoverflow.com/questions/13931081/why-focus-on-jtextfield-is-not-getting-on-the-first-click-of-tab-button), Focus, FocusSubsystem is pretty asynchronous, have to wrap into invokeLater | |
Re: there are two ways to use - JTable instead of plain JTextField - JFormattedTextField with number formatter, instead of set / parsing number valur from plain JTextField ________________________________________________________________________________________________________________________________________________________ you can to use JTextField with DocumentFilter (filtering of uinwanted char(s)) for number value | |
Re: - don't to recreate a new **JComboBoxes** instance inside **ItemListener**, then you lost referrence to the original **JComboBox** (fired event), create **JComboBox** only once time, - add **ItemListener** to both separatelly only to test **SELECTED** inside **public void itemStateChanged(ItemEvent ie)** - create **ItemListaner** class, there you determine which one firing … | |
Re: - use Swing instead of AWT (JFrame - Frame, JButton - Button, JComboBox - Choice...) - read [Oracle tutorial how to use JFormattedTextField](http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html), instead of parsing value from AWT TextField | |
Re: - for better help sooner post an [SSCCE](http://sscce.org/) - short, runnable, compilable, just to avoids any code came from Layer, MatrixLayer, jPanelVizualisationOptions1.update();, currentPanel.refresh(); - jList1.repaint(); is useless methods, sure required in the case that 1. JList isn't inside JScrollPanel, then to call revalidate & repaint to the JLists parent 2. … | |
Re: - for why reason you using AWT to use Swing instead - then Choice should be JComboBox, (Frame/JFrame, Button/JButton) - add ItemListener to JComboBox - ItemListener always fired twice events, SELECTED and DESELECTED, - can to determine, test if ITEM_STATE_CHANGED only | |
Re: - arrays in Programming languages starting with **zero**, - your **JTable** has **4 * 4 elements**, then **setValueAt(whatever, 3, 3)** could be last botton cell on left side - debug before if **items.A[5]** returns some value | |
Re: have to add **PrintRequestAttributeSet** before printing to **Printer** **PrintRequestAttributeSet set = new HashPrintRequestAttributeSet(); set.add(OrientationRequested.LANDSCAPE); Table_Stud.print(JTable.PrintMode.FIT_WIDTH, header, footer, false, set, false);** | |
Re: 1. this issue talking about remove then add a new **JComponents** to the (already) visible GUI, have to call **revalidate();** and **repaint();** for container where is placed ..., don't reacreate that on fly 2. load all **ImageIcons** on the Apps startup, store that as local variable 3. then you'll call … | |
Re: crossposted on coderanch | |
Re: 1. see [AutoComplete JComboBox](http://stackoverflow.com/a/7255918/714968) 2. see [how to interact betweens two JComboBoxes](http://www.daniweb.com/software-development/java/threads/363152/problem-w-multiple-jcombobox) |
The End.